c - 如何使用 C 中的函数查找给定字符的 ASCII 码?

标签 c

#include<stdio.h>

void ascii()
{
  //code goes here
}

int main()
{
    int b;
    char a;
    b=ascii(a);
    printf("%d",b);//Expecting the ASCII Value of a to printed.
    return 0;
}

期望 printf 语句给出 a 的 ASCII 值。

提前致谢。

最佳答案

不需要像 ascii() 这样的函数。出于这个目的,这有点矫枉过正,如果我可以这样说的话。

简单使用

char x = 'a';
printf("Symbol table index of %c is %d\n", x, x);

请注意,这仅在您的平台使用 ASCII 时有效 - 例如,对于具有 EBCDIC 字符集的 IBM 系统,这不会返回字符的 ASCII 值,您需要使用查找表。

关于c - 如何使用 C 中的函数查找给定字符的 ASCII 码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30485431/

相关文章:

php - 使用 popen 执行多处理脚本时输出困惑

c - 在C中正确分隔字符串

C - fscanf 未从文本文件中正确读取数字

c - 我必须为 SDL2 中的 SDL_GetClipboardText 等链接哪个文件?

c - C 中的按位运算 |=

c - 如何打印数组中的 100 个数字,然后使用 C 将它们相加

c - MPI : getting number of nodes (not processes) in a communicator

c - HackerRank 阶梯 C 困惑

c - 32位机器上 'double'结构成员的填充逻辑

c - 了解何时需要 malloc() : I know the length of char * n at compile time yet still seem to need malloc()