1.
2.
3.#include <stdio.h>//标准IO的头文件
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
int main(int argc,char **argv)
{
//argc存的是参数的个数
printf("argc=%d\n",argc);
if(argc != 4)
{
printf("你个傻逼,我只要两个参数\n");
return -1;
}
//argv存的是参数的字符串形式
//argv[0] ./a.out
//argv[1] 1.txt
//argv[2] 2.txt
//argv[3] 3.txt
//把第一个参数复制到第二个参数
int fd1 = open(argv[2], O_RDWR);//如果参数里出现了O_CREAT,
//那就需要多填一个mode_t类型的文件权限
if(-1 == fd2)
{
printf("打开%s失败,错误为%s\n",argv[2],strerror(errno));
}
int fd2 = open(argv[3], O_RDWR | O_CREAT,0777);
if(-1 == fd2)
{
printf("打开%s失败,错误为%s\n",argv[2],strerror(errno));
}
char buf[100];
while(1)
{
memset(buf,0,100);
int ret = read(fd2,buf,sizeof(buf)-1);
write(fd3,buf,strlen(buf));
if(0 == ret)
{
break;
}
}
close(fd2);
close(fd3);