#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<error.h>
int copy_file(FILE *src_fp,FILE *dest_fp)
{
if(src_fp==NULL)
{
perror("faile to open");
return -1;
}
if(dest_fp==NULL)
{
perror("faile to open");
return -1;
}
char buf[1024]={0};
int count =0;
while(fgets(buf,sizeof(buf),src_fp)!=NULL)
{
fputs(buf,dest_fp);
if(buf[strlen(buf)-1]=='\n')
count++;
memset(buf,0,sizeof(buf));
}
return count;
}
int main(int argc, const char *argv[])
{
int count = 0;
FILE* src_fp=fopen(argv[1],"r");
FILE* dest_fp=fopen(argv[2],"w");
count=copy_file(src_fp,dest_fp);
printf("%d %s\n",count,argv[2]);
fclose(src_fp);
fclose(dest_fp);
return 0;
}