#include <stdio.h>
#include <string.h>
void main()
{
int N,i,s;
char op;
scanf("%d",&N);
int a[N];
for(i=0;i<N;i++)
{
scanf("%d",&a[i]);
}
scanf("%c %d",&op,&s);
printf("%c %d",op,s);
}
如果我在代码中包含此 for
循环,然后执行此代码,scanf
不会读取我的输入。
如果我插入操作数 s 的值是 R 和 5,那么输出就是垃圾。
如果删除for
循环,那么我printf
打印正确的答案。
最佳答案
您需要使用尾随的 \n
字符。最简单的方法是编写:
scanf(" %c %d",&op,&s); //notice the space before %c
关于c - 我想保存 op=R 和 s=5,但我的代码显示垃圾输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25794441/