在C中将ASCII数转换为ASCII字符

Ano*_*ous 17 c ascii types

在C中有一种方法可以将输入为int的ASCII值转换为相应的ASCII字符作为char吗?

tas*_*oor 22

您可以分配intchar直接.

int a = 65;
char c = a;
printf("%c", c);
Run Code Online (Sandbox Code Playgroud)

实际上这也会奏效.

printf("%c", a);  // assuming a is in valid range
Run Code Online (Sandbox Code Playgroud)


Fre*_*Foo 16

如果iint,那么

char c = i;
Run Code Online (Sandbox Code Playgroud)

做到了char.<128如果来自不受信任的来源,您可能需要添加检查值.如果在您的系统上可用,最好使用isasciifrom <ctype.h>(参见@Steve Jessop对此答案的评论).