Weird problem with fwrite() and fread()
...actually with fread() only.
To begin with, I declared a structure, which consists of five unsigned int numbers. I generate random numbers for each record, and write the record to a file, using fwrite():
fwrite(&pent, sizeof(pent), 1, fl);
I repeat that n times. When all records are in the file, I close the file, and begin a function which reads those records.
And this is the momment when problem occurs. I read the record using fread():
fread(&pent, sizeof(pent), 1, fl);
I also repeat this n times.
After about (n/10 to n/2) reads, fread starts to return 0, because EOF occured ( I use feof() to check that).
How is it possible, that EOF occurs so early?! I know that there are n records in the file, so how can it be, that EOF is after (n/10 to n/2) reads?
Please help me!