C 语言实例 - 字符转 ASCII 码

既然根据 字符 查找对应 ASCII,那为什么不写一个 ASCII 转 字符 呢?两个互转不好吗?

下面是改进后的代码,菜鸟尽力,大佬勿喷。请多指教,谢谢。

#include

#define MAX_ASCII 127

int main()

{

char num,enter;

int temp=1;

for(;temp>0;)

{

printf("----------------------------\n");

printf("|** 开始 **|\n");

printf("|**ASCII 转 字符 按:1 **|\n");

printf("|**字符 转 ASCII 按:2 **|\n");

printf("|** 结束 按:0 **|\n");

printf("----------------------------\n");

scanf("%d",&temp);

if(temp==1)

{

printf("请输入数值小于 %d 的任意字符:",MAX_ASCII);

scanf("%d",&num);

printf("ASCII为 %d ,对应的字符为 %c \n",num,num);

}

if(temp==2)

{

printf("输入一个字符: \n");

scanf("%c", &enter); //回车键也算字符,所以这里使用其他变量替之.

scanf("%c", &num);

printf(" %c 的 ASCII 为 %d \n", num, num);

}

}

return 0;

}

big_tree big_tree

286***4460@qq.com

6年前 (2019-08-01)

万和VS美的热水器深度测评:哪款更适合你?|仙游这座大悲岩的历史传说和这八位神仙有关!