Home Forums C Programming Copy/Read/Write a binary file(.mp3) Reply To: Copy/Read/Write a binary file(.mp3)

#3384
Priyansh Agrawal
Participant

Well, that’s C++-code. In C this would look like that:

#include 

int main(int argc,char **argv)
{
int r=0,sz;
FILE *f1,*f2;
char buff[4096];

if (argc!=3)
{
r=1;
printf("usage: cop n");
}
else
{
if ((f1=fopen(argv[1],"rb"))==NULL)
{
r=2;
printf("cannot open input-file!n");
}
else
{
if ((f2=fopen(argv[2],"wb"))==NULL)
{
r=3;
printf("cannot open output-file!n");
}
else
{
while (!feof(f1))
{
sz=fread(buff,1,4096,f1);
fwrite(buff,sz,1,f2);
}

fclose(f2);
}

fclose(f1);
}
}

return r;
}