在 C 语言 中 toascii 函数 用于将传入的 字符 转为其 ACSII 码。
int toascii(int c);
参数 | 描述 |
---|---|
c | 要被转换为 ASCII 码的字母。 |
返回字符 c 的 ASCII 码。
使用 toascii 函数,需要引入 ctype.h 头文件。
使用 toascii() 函数,实现获取字符的ASCII码
#include <stdio.h>
#include <ctype.h>
int main()
{
printf("嗨客网(www.haicoder.net)\n\n");
char c1 = 'H';
char c2 = 'a';
char c3 = '8';
int c1ascii = toascii(c1);
int c2ascii = toascii(c2);
int c3ascii = toascii(c3);
printf("c1ascii = %d, c2ascii = %d, c3ascii = %d\n", c1ascii, c2ascii, c3ascii);
return 0;
}
程序运行后,控制台输出如下:
我们首先定义了三个字符,接着,我们使用了 toascii 函数,实现了将三个字符获取了其对应的 ASCII 码。
在 C 语言中 toascii 函数用于将传入的字符转为其 ACSII 码。