#include <stdio.h>
#include <stdlib.h>
#define BUFSIZE 1024
int main(int argc,char *argv[])
{
FILE *source,*des;
if(argc < 3)
{
fprintf(stderr,"Error Usage: no FILEanme input !\n");
exit(1);
}
if((source = fopen(argv[1],"r")) == NULL)
{
fprintf(stderr,"Couldn't open the file for %s \n",argv[1]);
exit(2);
}
if(setvbuf(source,NULL,_IOFBF,BUFSIZE) != 0)
{
fputs("Can't create output buffer \n",stderr);
exit(2);
}
if((des = fopen(argv[2],"w+"))== NULL)
{
fprintf(stderr,"Con't open %s\n",argv[2]);
exit(1);
}
fseek(source,0,SEEK_END);
int len = ftell(source);
rewind(source);
void *buffer = malloc(len);
fread(buffer,len,1,source);
fwrite(buffer,len,1,des);
if(fclose(source) !=0 || fclose(des) != 0)
{
printf("failed to closing!");
exit(1);
}
printf("copy finished bye.\n");
return 0;
}