#include<stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include<stdlib.h>
#include<fcntl.h>
#include<string.h>
int main(int argc,char **argv)//这里的指针存放的是文件地址
{
int fdNow;
int fdGoal;
char *readBuf=NULL;
if(argc!=3)
{
printf("Error!\n");
exit(-1);
}
fdNow=open(argv[1],O_RDWR);//第一个位置代表需要拷贝的内容
int n=lseek(fdNow,0,SEEK_END);//求取文件大小,为开辟readBuf做准备
lseek(fdNow,0,SEEK_SET);//光标回为
readBuf=(char *)malloc(sizeof(char)*n+2);
int n_read=read(fdNow,readBuf,n);
fdGoal=open(argv[2],O_RDWR|O_CREAT|O_TRUNC,0600);//第二个位置代表需要拷贝到什么地方,若那个地方原来有数据,则清除然后存放拷贝的内容。
write(fdGoal,readBuf,strlen(readBuf));
close(fdNow);
close(fdGoal);
return 0;
}
cp3.c里面的内容与cp2.c里面的一样