函数名:open
头文件:<io.h>
函数原型: int open(char *path,int access[,int auth]);
功能: 打开一个文件
参数:char *path 要打开的包含路径的文件名 ,int access 为打开方式 , int auth 为访问权限
返回值: 成功 返回文件句柄 ,失败 返回-1
程序例:打开一个文件,并输出提示
#include<stdio.h> #include<io.h> #include<fcntl.h> int main(void){ int fd=open("D:\\a.txt",O_RDWR+O_CREAT); if(fd==-1){ printf("can not open the file\n"); return 1; } printf("successful to open the file\n"); close(fd); return 0; }
运行结果
successful to open the file
本文固定URL:https://www.dotcpp.com/course/454