I compiled this code on my WxDev C++. By theory it should output the users’ answer and the correct answer. It did, with an exception of array number 0 of the coranswers array, showing just a blank space. I tried compiling it on other PCs and the problem wasn’t present. I tried reinstalling the WxDev, even as far as replacing it with codeblocks. Seems like the problem is on my PC. What should I do?
#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;
}
You don’t want to read a string into a char array