如何使用getchar将ASCII码转换成对应的int?

How to convert ASCII code to corresponding int using getchar?

我基本上想知道在第一个%d的最后一个printf语句中放什么,因为根据我的理解getchar将输入的字符转换为ASCII码。那么如何显示输入的字符呢?

#include <stdio.h>

int main(void) {
    int c;
    printf("Enter a character: ");
    c = getchar();
    printf("The ASCII code for the character %d is %d\n", what to put here, c);
    return 0;
}

您需要在 格式字符串 中提供 %c 格式说明符 而不是 %d

printf("The ASCII code for the character %c is %d\n", c, c);