We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi,
I'am using RL ARM Flash Filesystem V3.13 on Atmel AT91SAM7S256 processor. In the following example Reading a File (with 3 characters) the feof function reads everytime 4 characters.
here is my test programm:
void TestFsEof(void) { #define FNAME "F:Tst.bin" FILE *fout, *fin; // Write fout = fopen (FNAME, "w"); if (fout != NULL) { char Car = 'A'; for (int cnt=0; cnt<3; cnt++) { fwrite (&Car, sizeof(Car), 1, fout); Car++; } fclose (fout); } fin = fopen (FNAME, "r"); if (fin != NULL) { int RecNr = 0; char Car = 0; u32 Result; while (!feof (fin)) { Result = fread (&Car, sizeof (Car), 1, fin); //if (Result < 1) // break; // Checking EOF does not work, so i must check the Result from fread() TRACE(("\n\rRecNr:%d Car:%c", RecNr, Car )); RecNr++; } fclose (fin); } }
Thank you for any replies. Eugen
From the manual:
The feof function returns a nonzero value after the first read operation that attempts to read past the end of the file. It returns 0 if the current position is not end of file. There is no error return.
Your example works correctly according to the manual, but your code is wrong. Here is a modified code:
fin = fopen (FNAME, "r"); if (fin != NULL) { int RecNr = 0; char Car = 0; u32 Result; while (!feof (fin)) { Result = fread (&Car, sizeof (Car), 1, fin); TRACE(("\n\rRecNr:%d Car:%c", RecNr, Car )); RecNr += Result; } fclose (fin); }