#include<sys/types.h>
#include<sys/stat.h>
#include <fcntl.h>
#include<unistd.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char const *argv[])
{
int a, b;
char buff[64], buff1[58];
int fd = open("1.txt", O_RDWR); //打开1.txt
if(fd<0)
printf("open 1.txt error\n");
a = read(fd, buff, 64);//读取1.txt内容到buff
int fd1 = open("2.txt", O_RDWR);//打开2.txt
if(fd<0)
printf("open 2.txt error\n");
lseek(fd, 0, SEEK_SET);//定位到开头
b = write(fd1,buff,strlen(buff));//写入buff到fd1
close(fd);//关闭fd
close(fd1);//关闭fd1
return 0;
}
终端编译:gcc 文件名.c -o 文件名
执行文件:./文件名
查询文件:cat 1.txt