read in and write out

please tell me how to read in a .JPEG file, and rewrite it using a different filename? Please help…

Originally posted by happyhappy:
please tell me how to read in a .JPEG file, and rewrite it using a different filename? Please help…

Oh… how about something like:

FILE *in, *out;
char buff[1024];

in = fopen(“mypic.jpg”, “rb”);

out = fopen(“mypic2.jpg”, “wb”);

while (fread(buff, sizeof(buff), 1, in) > 0)
{
fwrite(buff, sizeof(buff), 1, out);
}

fclose(in);
fclose(out);

That’s just off the top of my head, so, watch for bugs.

If all you need is a copy, you could try
system(“copy file.jpg newfile.jpg”);