Open File:
We use fopen() function to open the existing file.
-If file is not exist then fopen() automatically create that file.
Syntax-
fp=fopen("Filename","mode");
Where,
fp is the file pointer.
Close file:
Syntax-
fclose(fp);
Create File pointer:
Syntax-
FILE *fp;
Example-
fp=fopen("Filename.txt","r"); //open file in read mode
fp=fopen("Filename.txt","w"); //open file in write mode
fp=fopen("Filename.txt","a"); //open file in append mode
fp=fopen("Filename.txt","r+"); //open file in read and write mode
fp=fopen("Filename.txt","w+"); //open file in read and write mode
program-
#include< stdio.h>
void main()
{
FILE *fp;
fp=fopen("Myfile.txt","r"); //open file in read mode
printf("Your file is createdn");
fclose(fp); // close file
printf("Your file is closed");
}
Your file is created
Your file is created