Hi,
Once I had a similar problem when I tried to read a binary file on a pc and I failed, but I was able to read it in Linux (there were actually different versions of the file), so I figured it's a corrupted file, thou the hex dump looked ok.
Now I'm having this problem with a different file, and on both, PC and Linux. The file structure is simple, int (4 bytes) and 15 ascii characters (15 bytes)
When I read it in I get the 1st and the 20th records right, all the rest of them show up wrong.
I'm attaching the binary file with extension .txt since .dat extension seems not to be a valid file extension for attachment on the forum. and I changed the extension in the code as well to reflect this change.
/* read.c */
#include <stdio.h>
#include <stdlib.h>
#define NAMELEN 15
typedef struct
{
int num;
//char junk[4];
char name[NAMELEN];
} rectype;
int main(int argc, char *argv[])
{
rectype rec;
FILE *f;
/* initialize */
f = fopen("extsort.txt","rb"); /* originally extsort.dat */
/* Temp */
int i;
for(i=1; i<35; ++i)
{
fread(&rec,sizeof(rectype),1,f);
printf("Record #%3d is %15d --> %-15s\n",i,rec.num,rec.name);
}
/* process each record in file */
//while (fread(&rec,sizeof(rectype),1,f) == 1)
//{
//printf(" %15d --> %-15s\n",rec.id,rec.name);
//}
/* finalize */
fclose(f);
system("PAUSE");
return EXIT_SUCCESS;
} /* main */
/* end read.c */
Thank you,
Waldis