#include
#include
#include
#include
#include
#include
int main() {
int fd = -1;
fd = open("zhidao_561804018.dat", O_CREAT | O_TRUNC | O_RDWR, 0666);
if (fd < 0) {
perror("open");
return -1;
}
char buff[64];
strcpy(buff, "Hello!I am writing to this file!");
int count = strlen(buff);
if (write(fd, buff, count) < 0) {
perror("write");
return -1;
}
if (lseek(fd, 0, SEEK_SET) < 0) {
perror("lseek");
return -1;
}
if (read(fd, buff, 10) < 0) {
perror("read");
return -1;
}
buff[10] = 0x00;
printf("%s\n", buff);
if (fd > 0) {
close(fd);
fd = -1;
}
return 0;
}