1,思维导图
2,使用read和write实现文件拷贝
#include<myhead.h>
int main(int argc, const char *argv[])
{
int fp1,fp2;
char a[1];
fp1=open("./1.txt",O_RDONLY);
fp2=open("./2.txt",O_CREAT|O_TRUNC|O_WRONLY,0664);
if(fp1==-1||fp2==-1)
{
perror("open");
return -1;
}
int c;
while(c=read(fp1,a,sizeof(a)))
{
if(write(fp2,a,sizeof(a))!=c)
{
break;
}
}
close(fp1);
close(fp2);
fp2=open("./2.txt",O_RDONLY);
if(fp2==-1)
{
perror("open");
return -1;
}
char n;
while(read(fp2,&n,sizeof(a))
{
printf("%c",n);
}
close(fp2);
return 0;
}