Write a program to copy the contents of one file to another.

#include <stdio.h>

int main(int argc , char *argv[])
{
FILE *src, *target;
char buffer[512];

if(argc != 3)
{
printf("\nToo few arguments. You must specify the filenames.");
return 1;
}

src = fopen(argv[1], "rb");
target = fopen(argv[2], "wb");
if(src == NULL || target == NULL)
{
printf("\nUnable to open \'%s\'",
src ? argv[2] : target ? argv[1] : "any file");
if(src) fclose(src);
if(target) fclose(target);
return 1;
}

while(fread((char *)buffer, sizeof(buffer) - 1, 1, src))
fwrite((char *)buffer, sizeof(buffer) - 1, 1, target);

fclose(src);
fclose(target);

return 0;
}

No comments:

Post a Comment

kiss on google ads if you are anonymous because your ip is trackable.thank you.

......from.admin