gpt4 book ai didi

c - 为什么我无法扫描%c字符?

转载 作者:行者123 更新时间:2023-11-30 21:15:29 25 4
gpt4 key购买 nike

c编程时,扫描字符串成功后,不是扫描字符。

char s[10],c;
scanf("%s",s);
scanf("%c",&c);
printf("%s\n",s);
printf("%c",c);

最佳答案

scanf手册:

specifier c:

Matches a sequence of characters whose length is specified by the maximum field width (default 1); the next pointer must be a pointer to char, and there must be enough room for all the characters (no terminating null byte is added). The usual skip of leading white space is suppressed. To skip white space first, use an explicit space in the format.

因此,将格式更改为“%c”

关于c - 为什么我无法扫描%c字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27061142/

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