我在 WxDev C++ 上编译了此代码。从理论上讲,它应该输出用户的答案和正确答案。确实如此,但 coranswers 数组的数组编号 0 除外,仅显示一个空格。我尝试在其他电脑上编译它,并没有出现问题。我尝试重新安装 WxDev,甚至用代码块替换它。看来问题出在我的电脑上。我该怎么办?
#include<stdio.h>
int main(){
char coranswers[20] = {'A', 'B', 'C', 'D', 'E', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A'};
char answers[20];
int count;
int grade = 0;
for(count = 0; count < 20; count++){
printf("No.%d ", count+1);
scanf("%s", &answers[count]);
}
for(count = 0; count < 20; count++){
printf("No.%d ", count+1);
printf("Your answers : %c\n", answers[count]);
if(answers[count] == coranswers[count]){
grade++;
}
else{
printf("Wrong answer, correct answer is %c\n", coranswers[count]);
}
}
return 0;
}
最佳答案
您不想将字符串读入字符数组
scanf("%s", &answers[count]); // the format string should be "%c"
关于c - 不同电脑不同输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14522572/