ASCII 表: ASCII值 ASCII值 ASCII值 ASCII值 空格(space) `(反引号)
学神之女
whi***08@outlook.com
本实例通过一些更改可以一次读取长字符,并一个一个显示 ASCII 码。
#include <stdio.h> #define MAX_STRING_LENGTH 65535 // 最大字符串长度 int main(){ char s[MAX_STRING_LENGTH]; printf("请输入长度小于 %d 的任意字符:",MAX_STRING_LENGTH); scanf("%s",s); // 读取字符串。 for(int i = 0; s[i]; i++){ printf("%c的ASCII:%d\t",s[i],s[i]); 学神之女 学神之女 whi***08@outlook.com5年前 (2018-06-05)
big_tree
286***4460@qq.com
既然根据 字符 查找对应 ASCII,那为什么不写一个 ASCII 转 字符 呢?两个互转不好吗?
下面是改进后的代码,菜鸟尽力,大佬勿喷。请多指教,谢谢。
#include <stdio.h> #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.com4年前 (2019-08-01)