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
。我想知道是否有糾正這個錯誤或任何更好的方式來比較這兩個字符和評分測試。