使用write和read完成文件的拷贝。
#include<myhead.h>
int main(int argc, const char *argv[])
{
if(argc != 3)
{
printf("传入参数错误\n");
return -1;
}
int fd1,fd2;
fd1 = open("./3.txt",O_RDONLY);
if(fd1==-1)
{
perror("open");
return -1;
}
fd2 = open("./4.txt",O_WRONLY|O_CREAT|O_TRUNC,0664);
if(fd2==-1)
{
perror("open");
return -1;
}
char buf[100];
int len = read(fd1,buf,sizeof(buf));
//printf("%s\n",buf);
write(fd2,buf,len);
close(fd1);
close(fd2);
return 0;
}