I am learning file I/O in C, and I watched a tutorial and saw this code:
#include <stdio.h>
#include <stdlib.h>
int main(){
FILE *inp;
char singleLine[100];
inp = fopen("text2.txt", "r");
while(!feof(inp)){
fgets(singleLine, 100, inp);
puts(singleLine);
}
fclose(inp);
return 0;
}
and here is the text file I created for practive:
text2.txt
Are you ok
Hi
How are you
I am fine
I understood most codes, but when I was implementing the code myself the last line of the text file kept showing up one more time like this:
Are you ok
Hi
How are you
I am fine
I am fine
And this was not the case in the tutorial. Please explain to me what the problem is, thank you