gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 11:04:11 26 4
gpt4 key购买 nike

我基本上想知道在第一个 %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);

关于c - 如何使用getchar将ASCII码转换成对应的int?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44176781/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com