ubuntu@ubuntu:~/IO/1$ gcc zy.c
ubuntu@ubuntu:~/IO/1$ ./a.out zy.c cp1
ubuntu@ubuntu:~/IO/1$ cat cp1
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
#include<errno.h>
void copy_file(FILE *src_file,FILE *dest_file)
{
char buf[150]={0};
char *ch;
while(1)
{
ch=fgets(buf,sizeof(buf),src_file);
if(NULL==ch)
break;
fputs(buf,dest_file);
}
}
int main(int argc, const char *argv[])
{
FILE *src_file;
FILE *dest_file;
if(argc!=3)
{
fprintf(stderr,"usage:%s fileName fileName\n",argv[0]);
return -1;
}
src_file=fopen(argv[1],"r");
if(NULL==src_file)
{
perror("Fail to fopen");
return -1;
}
dest_file=fopen(argv[2],"w+");
if(NULL==dest_file)
{
perror("Fail to fopen");
return -1;
}
copy_file(src_file,dest_file);
fclose(src_file);
fclose(dest_file);
return 0;
}
IO第一次作业
于 2023-04-10 20:41:12 首次发布