#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#define fileName "mm"
#define writeNum 128
#define readNum 12
//int open(const char *pathname, int flags);
//int open(const char *pathname, int flags, mode_t mode);
//ssize_t write(int fd, const void *buf, size_t count);
//ssize_t read(int fd, void *buf, size_t count);
// off_t lseek(int fd, off_t offset, int whence);
int main()
{
int fd;
int offset;
char readBuff[readNum] = {0};
fd = open(fileName,O_RDWR|O_CREAT,0755);//打开文件
if(fd == -1)//判断文件是否打开
{
printf("open file failed!\n");
perror("why");
return -1;
}
printf("open file success!\n");
offset = lseek(fd,2,SEEK_CUR);//偏移量
printf("offset is %d\n",offset);
read(fd,&readBuff,1);
printf("%s\n",readBuff);
close(fd);//关闭文件
return 0;
}