Reputation: 1271
for some reason fgets
reads lines from a file correctly until it reaches a certain line where it just gets part of the line. I checked the file with a Hex editor and there was no new line character in the middle of that line.
File:(pretty large. fgets
stops at line 269)
/mmc_data/add_rootfs
...
/mmc_data/add_rootfs/data/local/sbin/mcast
Here's the line 269 in Hexadecimal representation:
2f 6d 6d 63 5f 64 61 74 61 2f 61 64 64 5f 72 6f 6f 74 66 73 2f 64 61 74 61 2f 6c 6f 63 61 6c 2f 73 62 69 6e 2f 6d 63 61 73 74 0a
I'm just combining fgets
with printf
:
char cBuffer[1024]="";
while(fgets(cBuffer,1024,fpLog){
printf("%s\n",cBuffer);
}
...
The program outputs everything correctly until it reaches line 269 and it only prints:
/mmc_data/a
instead of
/mmc_data/add_rootfs/data/local/sbin/mcast
The 1024 Bytes have clearly not been reached as well as a new line character. So why is fgets stopping at that postion?
Upvotes: 2
Views: 846
Reputation: 1271
Solved: I created the file before attempting to access its contents. I did not want to close the file. So the last portion stayed in the buffer and was not written to the file. I solved the issue by using fflush(fpLog)
between the writing and the reading
Upvotes: 4