Look up fread and fwrite.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
Off the top of my head, I suspect that the fscanf is reading too many or not enough bytes.
I recommend that you either treat the whole file as binary or treat the whole file as ASCII.
Where you do fprintf(fp, "%d\n", i) and fscanf(fp, "%d", &i) you could just as easily use fwrite(&i, 1, sizeof(i), fp) and fread(&i, 1, sizeof(i), fp) . The amount read/written would be far more consistent.
Murtan
Practically a Master Poster
671 posts since May 2008
Reputation Points: 344
Solved Threads: 116
Yes, functions that take a void * will accept any pointer type as they have no expectations of the pointer.
Murtan
Practically a Master Poster
671 posts since May 2008
Reputation Points: 344
Solved Threads: 116