前置知识:[[标准IO]] 详细系统调用请查阅man手册

open()

打开文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# include <unistd.h> // close函数
# include <fcntl.> // open函数
# include <stdio.h>

int main(int argc, char* argv[])
{
int fd = open("./dict.txt",O_RDONLY); // 以只读模式打开dict.txt,参数里面是字母O,不是数字0
// int fd = open("./dict.txt",O_RDONLY|O_CREAT, 0644); // 创建并打开文件dict.txt,设置权限为:rw-r--r--
if(fd==-1)
{
printf("file open error!");
}
close(fd); // 关闭文件描述符
return 0;
}

close()

关闭文件 见上述代码