Function name : open
Header file : <io.h>
Function prototype : int open(char *path,int access[,int auth]);
Function : Open a file
Parameters : char *path The file name containing the path to be opened, int access is the opening method, int auth is the access permission
Return value : Returns the file handle on success, -1 on failure.
Program example : Open a file and output prompts
#include<stdio.h>#include<io.h>#include<fcntl.h>intmain(void){intfd=open(D:\a.txt,O_RDWR+O_CREAT);if(fd==-1 ){printf(cannotopenthefilen);return1;}printf(successfultoopenthefilen);close(fd);return0;}
Running results
successfultoopenthefile