I am doing a C project related to my lesson. I need to read words from a file named file2.txt whose content:
file2.txt:
stephen elis elis
awkward
hello bye
stephen ayse
goodbye
book picture pencil
I am using:
FILE *file = fopen("file2.txt" , "r");
char word[15];
while(!feof(file))
{
fscanf(file,"%s",word);
printf("%s" , word);
printf("\n");
}
But when the words are printed the result is:
stephen
elis
elis
awkward
hello
bye
stephen
ayse
goodbye
book
picture
pencil
pencil --> printed second time
Thus , last word is printed twice and I do not understand why. Please help me about fixing this error because time is limited to complete this error! Thank you...