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

Viewing 1 reply thread
  • Author
    Posts
    • #2095
      alok roy bithi
      Participant

      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

    • #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;
      }
Viewing 1 reply thread
  • The forum ‘C Programming’ is closed to new topics and replies.