#include<stdio.h>
int main()
{
char ch;
int i;
scanf("%c", &i);/* i know this must be reversed for next input but I want to know the impact of this code if we use scanf type char for integer data type*/
scanf("%d", &ch);
printf("%c %d", ch, i);
return 0;
}
没有错误,但为什么没有获取第二个 scanf() 语句的输入
最佳答案
您将 i
声明为 int
,将 ch
声明为 char
在您的 scanf
中,您有 %c
代表 i
和 %d
代表 ch
而 %c
用于 char
,%d
用于 int
。
所以只要把它们转过来就可以了。
使用printf
,您将获得正确的格式。
关于c - 没有错误,但为什么我们没有得到第二个 scanf() 语句的输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41628677/