hi all, i'm so mess up w/ this pro.
suppose a data file File.dat:
a b c d e
f g
how can i stop read those character when matching the newline?
note: # of words must be counted
my code:
thanx for any help!!Code:int main() { char word; FILE *in; in=fopen("File.dat","r"); int i=0; while(fscanf(in, "%c", &word)!=EOF) { printf("%c\n", word); if(word=='\n'){ break; printf("newline matched, stop reading file!\n"); } i++; } printf("%d words are read, bye\n", i); fclose(in); return 0; }