#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
int main(int argc, const char *argv[])
{
pid_t pid = fork();
if(pid<0)
{
perror("");
return -1;
}
else if(pid==0)
{
sleep(1);
FILE *fp=fopen("a.txt","r");
FILE *fp1=fopen("b.txt","a+");
char str[10]="";
fseek(fp,5,SEEK_SET);
fread(str,5,1,fp);
printf("%s",str);
fputs(str,fp1);
fclose(fp);
fclose(fp1);
printf("好好学习\n");
}
else
{
FILE *fp=fopen("a.txt","r");
FILE *fp1=fopen("b.txt","r+");
char str[10]="";
fread(str,5,1,fp);
printf("%s",str);
fputs(str,fp1);
fclose(fp);
fclose(fp1);
printf("天天向上\n");
}
return 0;
}
DAY50530
最新推荐文章于 2024-08-02 20:00:38 发布