question



I wrote this small program to read a 512 block of binary data and write
the same to a file. My code compiled well. The only thing is when I ran the
compilers binary instead of a data file of 512 bytes I got one of 2048
bytes.

#include <stdio.h>

main(){
int buf[512];
FILE *fp;
fp=fopen("r.dsk","rb");
if (fp==NULL) {printf("Error"); exit(0);}
fread(buf,sizeof(int),512,fp);
fclose(fp);
fp=fopen("dat","wb");
if (fp==NULL) {printf("Error");}
fwrite(buf,sizeof(int),512,fp);
fclose(fp);}

Is it the code or some overhead from the compiler or linker?

Bill
The unix dd command copies exactly 512 bytes of I asked it too.


.



Relevant Pages

  • Re: question
    ... I wrote this small program to read a 512 block of binary data and write ... compilers binary instead of a data file of 512 bytes I got one of 2048 ... Here, you read up to 512 int-sized values, and discard the return ... Why are you writing 512 of these, regardless of how many were read? ...
    (comp.lang.c)
  • Re: question
    ... I wrote this small program to read a 512 block of binary data and ... compilers binary instead of a data file of 512 bytes I got one of 2048 ... Here, you read up to 512 int-sized values, and discard the return ... I guess I could've used it instead of int ...
    (comp.lang.c)
  • Re: Nice to have feature in upcoming Fortran compilers...
    ... that that was insufficient. ... And some compilers do use unsigned one-byte integers. ... To simplify portable handling of binary data, it would be nice to have an unsigned 8-bit byte type guaranteed by the standard. ...
    (comp.lang.fortran)
  • Re: Pure TCL implementations
    ... Helmut Giese wrote: ... But it can't produce binary data yet, ... parsers, neither with compilers. ... Pozdrawiam! ...
    (comp.lang.tcl)
  • Re: Will HLA2.0 Support rosasm?
    ... >>It'd be like the Masm team trying to stop HLA calling it to compile ... > - You just implement a Command Line holding in RosAsm Source, ... They don't have Java compilers inside of them, ...
    (alt.lang.asm)