作业:使用write和read完成文件的拷贝。
#include <myhead.h>
int main(int argc, const char *argv[])
{
int fd1,fd2;
fd1 = open("./1.txt",O_RDONLY);
if(fd1==-1)
{
perror("open1");
return -1;
}
fd2 = open("./2.txt",O_TRUNC|O_WRONLY);
if(fd2==-1)
{
perror("open2");
return -1;
}
int len;
char a;
while(1)
{
len=read(fd1,&a,1);
if(len==0)
{
break;
}
write(fd2,&a,1);
}
close(fd1);
close(fd2);
return 0;
}
X-mind