Im trying to write a program that will search a surname in database of students and print whole line where that surname is. Every time I run it, it says No Match.
void search(){
FILE *file;
file = fopen("students.txt", "r");
char sSurrname[100];
char id[10];
char name[10];
char the_name[100];
char surrname[10];
char phone[10];
char the_surrname[100];
char phone_number[100];
int the_id;
printf("Type searched surrname: ");
scanf("%s", &sSurrname);
while (!feof(file)){
fscanf(file, "%s %d || %s %s || %s %s || %s %s ||", &id, &the_id, &name, &the_name, &surrname, &the_surrname, &phone, &phone_number);
if (strcmp(sSurrname, the_surrname) == 0) {
printf("%s %d || %s %s || %s %s || %s %s ||", &id, &the_id, &name, &the_name, &surrname, &the_surrname, &phone, &phone_number);
break;
} else {
printf("No Match.");
break;
continue;
}
This is the database:
ID: 0 || Name: Pepa || Surrname: Hnatek || Phone: 321 ||
ID: 1 || Name: Jan || Surrname: Novak || Phone: 123 ||