输入一个字母,输出与之对应的ASCII值

输入一个字母,输出与之对应的ASCII值 #include int main() { char a; printf("请输入一个字母:"); scanf("%c",&a); printf("%c的ASCII为%d",a,a); return 0; } 在PTA上总是显示答案错误 a.c: In function ‘main’: a.c:6:5: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result] scanf("%c",&a); ^~~~~~~~~~~~~~

应该是pta平台的问题吧,这个代码没有问题。

scanf("%c",&a);

改为

int b = scanf("%c",&a);

试试。

#include<stdio.h>
int main() {
    char a;
    int x = scanf("%c",&a);
    printf("%d",a);
    return 0;
}

 

试过了,还是不行啊

scanf("%c",&a);

改为

int b = scanf("%c",&a);

就正常了。

不同的平台安全性检查规则不一样,warning可以忽略。代码没啥毛病。

您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632