0
我有一个程序,其中有一个名为students
的10 struct
变量的数组。在students
我有一个char
数组变量称为testAnswers
与20个元素。我想要做的是将这十名学生的testAnswers
与char
数组变量answers
与20个元素进行比较。基本上,变量answers
是学生testAnswers
的答题卡。答案都是真/假。这是我到目前为止有:使用带char和结构数组的strcmp时出错
注:numStu
是10和numAns
是20
void checkAnswers(char answers[], student students[]){
for (int i = 0 ; i < numStu ; i++){
for (int d = 0 ; d < numAns ; d++){
if (students[i].testAnswers[d] == ' '){
students[i].score += 1 ; //if the student did not answer the question add 1 which will be substracted once if loop sees it is not correct resulting in the student losing 0 points.
}
if (strcmp(answers[d],students[i].testAnswers[d]) == 0){
students[i].score +=2 ;//if the student answer is correct add 2 points to score
}
if (strcmp(answers[d],students[i].testAnswers[d]) != 0){
students[i].score -= 1 ; //if the student answer is incorrect substrct 1 point
}
}//end inner for
}//end for outer
}//end checkAnswers
我继续错误接收:
invalid conversion from char to const char
initializing argument 1 of `int strcmp(const char*, const char*)'
对于这两种情况下,我用strcmp
。我想知道是否有纠正这个错误或任何更好的方式来比较这两个字符和评分测试。