Fopen, Fclose, Gets, Fputs Functions in C
Fopen, Fclose, Gets, Fputs Functions in C
Fopen, Fclose, Gets, Fputs Functions in C
fopen()
fopen()fopen() function is used to open a file to perform operations such as reading, writing etc. In a C program, we
declare a file pointer and use fopen() as below. fopen() function creates a new file if the mentioned file name does
not exist.
FILE *fp;
Where,
fp – file pointer to the data type “FILE”.
filename – the actual file name with full path of the file.
mode – refers to the operation that will be performed on the file. Example: r, w, a, r+, w+ and a+. Please refer
below the description for these mode of operations
fclose()
fclose() function closes the file that is being pointed by file pointer fp. In a C program, we close a file as
below.
fclose (fp);
fscanf(fp,”format specifiers”,arguments);