#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main()
{
int fd,a;
fd = open("./33.txt",O_RDWR);
if(fd == -1)
{
perror("open error\n");
return -1;
}
char buf[12]={0};
printf("Please write the name who are you terrible.\n");
printf("The name don't more than 12 letter.\n");
scanf("%s",buf);
write(fd,buf,12);
char ahr[100]={0};
lseek(fd,0,SEEK_SET);
a = read(fd,ahr,100);
if(a == -1)
{
perror("read error\n");
return -1;
}
printf("%s\n",ahr);
printf("Do you like this kidding?\n");
}
你的打开方式可能是写入时会覆盖原有内容的方式