#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
int main()
{
char buf[128] = "";
// open的第一个参数:要打开文件的路径;第二个:O_RDONLY:只读模式
int fd = open("/exsample/filea", O_RDONLY);
// lseek的第一个参数:文件描述符;第二个:偏移量;第三个:SEEK_SET:为0时表示文件开始位置
int ret = lseek(fd, 0, SEEK_SET);
// read的第一个参数:文件描述符;第二个:读出数据的一段内存空间;第三个:每次读取的字节数,并且读取的字节不能超过buf剩余的空间大小
ret = read(fd, buf, sizeof(buf));
for (int i = strlen(buf) - 1; i >= 0; i--)
printf("%c", buf[i]);
return 0;
}
结果: