Vote count: 0 I am leaing how to handle files in C. When I try to read a binary file, everything runs fine but I get a garbage output. Here is my code: FILE *ptr; struct file rec; ptr=fopen("sample.bin","rb"); while(!feof(ptr)) { fread(&rec,sizeof(struct file),1,ptr); printf("%d, %d, %d, %d, %f, %x, %s, %f, %c, %d, %u, %d, %x, %d, %d, %u, %fn", rec.a, rec.b, rec.c, rec.d, re.e, rec.f,rec.g, rec.h, rec.i, rec.j, rec.k, rec.l,rec.m, rec.n, rec.o, rec.p, rec.q); } So I am thinking I might need to use more than one fread(). Can Someone show me how to use it? Note:This is how the sample.bin looks like: 0000 0000 0101 002f 1000 0000 00f4 0d0a 4540 8f94 e9ff ffff ffff 636c 6f63 6b00 00c0 ece0 3b69 ...
ادامه مطلب