C语言实现输入ascii码,输出对应的字符

源代码

/**********  ascii.c  ************/
#include
#include
//下面的字符串总共有714个字符。
char strs[714]= "0,NUL,16,DLE,32, ,48,0,64,@,80,P,96,`,112,p,1,SOH,17,DC1,33,!,49,1,65,A,81,Q,97,a,113,q,2,STX,18,DC2,34,\",50,2,66,B,82,R,98,b,114,r,3,ETX,19,DC3,35,#,51,3,67,C,83,S,99,c,115,s,4,EOT,20,DC4,36,$,52,4,68,D,84,T,100,d,116,t,5,ENQ,21,NAK,37,%,53,5,69,E,85,U,101,e,117,u,6,ACK,22,SYN,38,&,54,6,70,F,86,V,102,f,118,v,7,BEL,23,ETB,39,',55,7,71,G,87,W,103,g,119,w,8,BS,24,CAN,40,(,56,8,72,H,88,X,104,h,120,x,9,HT,25,EM,41,),57,9,73,I,89,Y,105,i,121,y,10,LF,26,SUB,42,*,58,:,74,J,90,Z,106,j,122,z,11,VT,27,ESC,43,+,59,;,75,K,91,[,107,k,123,{,12,FF,28,FS,44,,,60,<,76,L,92,\\,108,l,124,|,13,CR,29,GS,45,-,61,=,77,M,93,],109,m,125,},14,SO,30,RS,46,.,62,>,78,N,94,^,110,n,126,~,15,SI,31,US,47,/,63,?,79,O,95,_,111,o,127,DEL,";
char words[128][5];//共有128个ascii码字符
int main(){
	int len = strlen(strs);
	//printf("len=%d\n",len);
	int i = 0;
	int j = 0;
	int result = 0;
	memset(words,0,sizeof(words));
	while(i < len) //strs的长度(字符的个数)
	{
		result = 0;
		while(strs[i] != ',' && i < len)
		{
			result = result * 10 + (strs[i++] - '0');//计算对应的ascii十进制数值
		}
		i++;
		j = 0;
		while(strs[i] != ',' || i == 548) //逗号","本身作为分隔符存在,但是逗号本身也是一个ascii符号,这里需要做一下特殊处理,逗号对应的字符在strs中的下标是548
		{
			words[result][j++] = strs[i++];
		}
		//printf("%d\n%s\n----------------\n",result,words[result]);
		i++;
	}
	int a = 0;
	while(scanf("%d",&a)) //开始输入十进制的ascii码
	{
		printf("%s",words[a]);
	}
	return 0;
}

 

 

C语言实现输入ascii码,输出对应的字符_第1张图片

你可能感兴趣的:(C)