一、思维导图
二、习题
#include <myhead.h>
int main(int argc, const char *argv[])
{FILE *fp=NULL;FILE *fq=NULL;pid_t pid=fork();if(pid>0){if((fp=fopen("./text.txt","r"))==NULL){perror("fopen error");return -1;} if((fq=fopen("./text1.txt","w"))==NULL){perror("fopen error");return -1;}//计算文件大小fseek(fp,0,SEEK_END);size_t size=ftell(fp);fseek(fp,0,SEEK_SET);char str[5]="";//读取复制文件内容while(fgets(str,sizeof(str),fp)!=NULL){fputs(str,fq);if(ftell(fp)==size/2){break;}}fclose(fp);fclose(fq);}else if(pid==0){//在子进程中打开复制文件if((fp=fopen("./text.txt","r"))==NULL){perror("fopen error");return -1;}fseek(fp,0,SEEK_END);size_t size=ftell(fp);fseek(fp,size/2,SEEK_SET);//在子进程中打开目标文件if((fq=fopen("./text1.txt","a"))==NULL){perror("fopen error");return -1;}char str1[5]="";//从文件中间位置读取数据,存入到数组中while(fgets(str1,sizeof(str1),fp)!=NULL){//将数据写入目标文件fputs(str1,fq);}fclose(fp);fclose(fq);exit(0);}wait(NULL); return 0;
}