#include
#include
#include
#ifdef BUFSIZ
#undef BUFSIZ
#define BUFSIZ 4096
#endif
int main(int argc,char **argv)
{
char buf[BUFSIZ];
int msglen;
if(argc!=3||strcmp(argv[1],argv[2])==0)
{
fprintf(stderr,"********************************\n\n");
fprintf(stderr,"Please usage:%s source_file destination_file\nAnd source_file is different from destination_file\n\n",argv[0]);
fprintf(stderr,"********************************\n");
exit(0);
}
FILE *fp_src,*fp_des;
if((fp_src=fopen(argv[1],"r"))==NULL)
{
fprintf(stderr,"open %s failed!\n",argv[1]);
exit(1);
}
if((fp_des=fopen(argv[2],"w"))==NULL)
{
fprintf(stderr,"open/create %s failed!\n",argv[2]);
exit(2);
}
while(fgets(buf,BUFSIZ,fp_src)!=NULL)
{
if(fputs(buf,fp_des)==EOF)
{
fprintf(stderr,"copy %s to %s failed!\n",argv[1],argv[2]);
exit(3);
}
}
printf("copy %s to %s successful!\n",argv[1],argv[2]);
return 0;
}