I have a text file with this content:
what to write
I first created this file like this:
FILE * fPointer;
fPointer = fopen("fileName.txt" , "w"); //create the file
fprintf(fPointer,"what to write\n"); //write to the file
I read the file content like this:
fPointer = fopen("fileName.txt" , "r"); //too read the file
char singleLine [100];
while(!feof(fPointer)){ //while file is not finished
fgets(singleLine,100,fPointer);
puts(singleLine);
}
I expected to get the "what to write" content of the file only once but this is the result:
As you can see, for some reason I am getting the file content 2 times, any ideas on why this may happen?
I have checked that the file location is correct and that the file exists.
I have also checked this answer but I am not familiar with the
getc
method and I want to know what I am doing wrong.