Function name : close
Header file : <io.h>
Function prototype : int close(int handle);
Function : Used to close the file opened by the open() function
Parameter : int handle The file handle returned when opening the file
Return value : 0 on success, -1 on failure
Program example : Close the file opened by the open function and output a prompt
#include<stdio.h>#include<io.h>#include<fcntl.h>intmain(void){intfd=open(D:\a.txt,O_RDONLY+O_CREAT);if(fd==-1 ){ printf(cannotopenthefilen);return1;}char*str=(close(fd)==0)?successfulclose:failclose;printf(%sn,str);return0;}
Running results:
successfulclose