Why does this work?
Is the function of the semicolon after the while that the strcmp in the while compare's "zoekterm" with the previous "naam" and not that is loaded in that current execution of the while statement?
example of a textfile:Code:#include <stdio.h> #include <string.h> #define MAX 81 void main() { char naam[MAX]; char zoeknaam[MAX]; int leeftijd; FILE *fptr; fptr=fopen("c:/c/fprintf.txt","r"); if (fptr != NULL) { printf("Van welke persoon wil je de leeftijd kennen?\n"); scanf("%s",zoeknaam); while (fscanf (fptr,"%s %d",naam, &leeftijd) != EOF && strcmp(naam,zoeknaam)!=0); { if (strcmp(naam,zoeknaam)==0) { printf("\nNaam: %s\n", naam); printf("Leeftijd: %d\n\n", leeftijd); } else { printf("persoon niet gekend\n"); } fclose(fptr); } } else { printf("fout bij openen file\n"); } }
Code:bert 19 sylvie 17 koen 19 jimmy 19 jelle 19




Reply With Quote