Home › Forums › C Programming › Copy/Read/Write a binary file(.mp3) › Reply To: Copy/Read/Write a binary file(.mp3)
April 28, 2008 at 9:42 am
#3384
Priyansh Agrawal
Participant
Well, that’s C++-code. In C this would look like that:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | #include <br /> <br /> int main(int argc,char **argv)<br /> {<br /> int r=0,sz;<br /> FILE *f1,*f2;<br /> char buff[4096];<br /> <br /> if (argc!=3)<br /> {<br /> r=1;<br /> printf("usage: cop n");<br /> }<br /> else<br /> {<br /> if ((f1=fopen(argv[1],"rb"))==NULL)<br /> {<br /> r=2;<br /> printf("cannot open input-file!n");<br /> }<br /> else<br /> {<br /> if ((f2=fopen(argv[2],"wb"))==NULL)<br /> {<br /> r=3;<br /> printf("cannot open output-file!n");<br /> }<br /> else<br /> {<br /> while (!feof(f1))<br /> {<br /> sz=fread(buff,1,4096,f1);<br /> fwrite(buff,sz,1,f2);<br /> }<br /> <br /> fclose(f2);<br /> }<br /> <br /> fclose(f1);<br /> }<br /> }<br /> <br /> return r;<br /> } |