String comparisons don't work this way in C. Use the strcmp
function from the string.h header. strcmp
returns 0
to indicate equality.
while (strcmp(name, "FINISH") != 0)
As an added note, if you want to run this multiple times, reading in the first name and grade, then starting your loop doesn't make much sense. An "infinite loop" with a break if FINISH
is entered makes more sense.
int main() {
int score, count = 0;
char name[10];
while (1) {
printf("please enter your name and score by order(enter FINISH in name to end)-->");
scanf_s("%s%d", name, 10, &score);
if (strcmp(name, "FINISH") == 0) break;
// Do something with this data
}