作业:使用write和read完成文件的拷贝
#include<myhead.h>
int main(int argc,const char*argv[])
{
if (argc != 3)
{
perror("error");
return 1;
}
int fd = open("1.txt", O_RDONLY);
if (fd == -1) {
perror("open");
return -1;
}
int fd1 = open("2.txt", O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (fd1 == -1) {
perror("open");
return -1;
}
char buf[200];
int len;
while((len=read(fd, buf, sizeof(buf)))>0)
{
write(fd1, buf, len);
}
close(fd);
close(fd1);
return 0;
}