c - 不同电脑不同输出

标签 c arrays dev-c++

我在 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/

相关文章:

c - 数组元素之间的最短差异

c - 结构体指针作为返回类型

python - 以更 Pythonic 的方式修改这个简单的数组创建函数

c++ - 在 Windows 7 中使用用于 Dev-C++ 的 cURL 库时遇到问题

c - 编译C代码的问题

c++ - 函数原型(prototype)中的参数名称

C printf 格式字符串

c - 如果文件名在 DOS 8.3 风格中相同,则 MoveFile 和 MoveFileEx 工作异常

javascript - 如何用双括号声明数组

javascript - 如何制作包含其他值的值数组?