Используйте strcmp в C, чтобы проверить Введенное имя
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <conio.h> #include <stdlib.h> #include <string.h> #define cnit105 100 //Structure struct Student { char name[20]; int score; }; struct Student StudentRecord[cnit105]; //Construct Array/Count/Average void display_array(int k) { int sum = 0; int i; double avgScore; printf("\nThe number of students entered : %d\n\n", k); printf("Name\tScore\n"); printf("========================\n"); for (i = 0; i<k; i++) { printf("%s\t%d\n", StudentRecord[i].name, StudentRecord[i].score); sum = sum + StudentRecord[i].score; } avgScore = (double)sum / k; printf("\nAverage score is %0.2f\n", avgScore); } //Main int main() { int i = 0; int count = 0; displayMyInfo(); //Display's Information while (1) { printf("\nEnter student's test score, -1 to stop data entry: "); scanf("%d", &StudentRecord[i].score); if (StudentRecord[i].score == -1) { break; } printf("Enter the name: "); scanf("%s", StudentRecord[i].name); count = count + 1; i++; } display_array(count); //Display's Array and Count if(strcmp(StudentRecord[i].name, "Zolo")==0) { printf("\nZolo was found.\nZolo's score is %s", StudentRecord[i].score); } else { printf("\nZolo was not found."); } _getch(); return 0; }
Что я уже пробовал:
Я много пробовал, и, кажется, ничего не работает. Мне нужно, чтобы он вывел "Золо был найден" и соответствующую оценку, которая была ему дана. Но только если было введено слово "Zolo".
Если "Золо" не был введен, то это будет выход "Золо не найдено."
jeron1
Может быть, расскажете нам, что он делает и чем отличается от того, что вы ожидаете. Вы можете использовать отладчик?