Hi,
I'm a newbie............ Sorry, if I violate any norms.

Is it possible to copy any audio file or image file using C language? I think it is possible. If anyone knows it please guide me.
If you know the code, that 'll be helpful.

you can copy any file, whatever the type or extension.

just open the source file as a binary file and use a while loop to copy each byte one at a time to the destination, until the EOF charater is found.

see fopen(), fgetc(), fputc(), and feof() in the standard C library <stdio.h>. that's all the functions you'll need, though you'll probably want to include error checking with ferror().


.

Edited 6 Years Ago by jephthah: n/a

just open the source file as a binary file and use a while loop to copy each byte one at a time to the destination, until the EOF charater is found.

copying byte by bye using loop...uh...sounds like a complected process...:|

Edited 6 Years Ago by urbangeek: n/a

copying byte by bye using loop...uh...sounds like a complected process...:|

uh... not so much :)

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
   FILE *fp_source, *fp_dest;
   char oneByte;

   /* WARNING:  this does ZERO error checking!! */

   fp_source = fopen(argv[1], "rb"));
   fp_dest   = fopen(argv[2], "wb"));

   while(!feof(fp_source)) {
      oneByte = fgetc(fp_source);
      fputc(oneByte, fp_dest);
   }

   fclose(fp_source);
   fclose(fp_dest);

   return 0;
}

.

Edited 6 Years Ago by jephthah: n/a

uh... not so much :)

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
   FILE *fp_source, *fp_dest;
   char oneByte;

   /* WARNING:  this does ZERO error checking!! */

   fp_source = fopen(argv[1], "rb"));
   fp_dest   = fopen(argv[2], "wb"));

   while(!feof(fp_source)) {
      oneByte = fgetc(fp_source);
      fputc(oneByte, fp_dest);
   }

   fclose(fp_source);
   fclose(fp_dest);

   return 0;
}

.

How about stopping the loop without the !eof() ? eof() is not a good solution as the exit control of a loop. EOF would be true only after it is read and not when it is reached. char oneByte; must be an int, since fgetc() returns an int, and it is not a guarantee that char would be signed.

Edited 6 Years Ago by Aia: n/a

How about stopping the loop without the !eof() ? eof() is not a good solution as the exit control of a loop. EOF would be true only after it is read and not when it is reached. char oneByte; must be an int, since fgetc() returns an int, and it is not a guarantee that char would be signed.

That sounds good dude......

Working nicely. Thanks a lot

How about stopping the loop without the !eof() ? eof() is not a good solution as the exit control of a loop. EOF would be true only after it is read and not when it is reached. char oneByte; must be an int, since fgetc() returns an int, and it is not a guarantee that char would be signed.

you're right about the byte should be type int, not char. it may possibly fail for some compilers. i don't know why i keep doing that, i know better.

however, i disagree with you about the eof() .. i think that's a valid way to exit the loop. unless you can remind me why it's not.

Edited 6 Years Ago by jephthah: n/a

however, i disagree with you about the eof() .. i think that's a valid way to exit the loop. unless you can remind me why it's not.

A `reminder'

Comments
Yuppie, that's what they often forget :p
bada bing
This question has already been answered. Start a new discussion instead.