Home › Forums › C Programming › Copy/Read/Write a binary file(.mp3)
- This topic has 1 reply, 2 voices, and was last updated 16 years, 8 months ago by Priyansh Agrawal.
Viewing 1 reply thread
- AuthorPosts
- April 20, 2008 at 11:50 pm #2095alok roy bithiParticipant
Hi all,
The job is to read a .mp3 binary file and create(write) a new .mp3 file which is same as the original file. So, the basic thing we will be trying to do is to read/write of binary file(.doc, .pdf, .xls, .mp3). So the code should finally create a binary file(say a .mp3), which when opened with a player, should be recognized and played correctly.
Has anyone worked on this?
I mean, it will be appreciating if they can help me in getting started with this.
Regards
Swapna - April 28, 2008 at 9:42 am #3384Priyansh AgrawalParticipant
Well, that’s C++-code. In C this would look like that:
1234567891011121314151617181920212223242526272829303132333435363738394041424344#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 />}
- AuthorPosts
Viewing 1 reply thread
- The forum ‘C Programming’ is closed to new topics and replies.