Function name : create
Header file : <io.h>
Function prototype : int creat(const char *file,int auth);
Function : Create a file with the specified file name
Parameters : char *file The name of the file to be created, int auth is the operation permission
Return value : Returns the file handle on success, -1 on failure.
Program example : Create a file and then enter the content. The file created by this function cannot overwrite the file with the same name.
#include<stdio.h>#include<io.h>#include<fcntl.h>intmain(void){charfilename[80];printf(inputfilepathandfilename,egd:\a.txt:);gets(filename); intfd=creat(filename,O_RDONLY);if(fd==-1){printf(cannotcreatethefilen);return1;}printf(successfultocreatethefilen);close(fd);return0;}
Running results
inputfilepathandfilename,egd:a.txt:d:c.txtsuccessfultocreatethefile