The question:Why do i have to write if(c!=EOF) statement again in do-while block in the following code?
The thing is that if i don't write the if(c!=EOF)again in the block,it outputs the last word again in the end.Can you tell me why that is happening?
Code:#include<stdio.h> main() { FILE*pt; char array[100]; int c; pt=fopen("text.txt","r"); if(pt==NULL) printf("the file doesn't exist"); else { do { c=fscanf(pt,"%s",array); if(c!=EOF) printf("%s",array); } while(c!=EOF); } fclose(pt); }