fclose() function is C library function and it's used to releases the memory stream, opened by fopen() function.
Syntax:- fclose( FILE * stream );
Note :- C fclose returns EOF in case of failure and returns 0 on success.
Example;-
#include<stdio.h>
int main()
{
FILE *fp;
fp = fopen("file1.txt","w");
fprintf(fp, "%s", "helloworld");
fclose(fp);
return 0;
}
Explanation:-
The above example will create a file called file1.txt.
The w means that the file is being opened for writing, and if the file does not exist then the new file will be created.
The fprintf function writes helloworld to the file.
The fclose function closes the file and releases the memory stream.
Syntax:- fclose( FILE * stream );
Note :- C fclose returns EOF in case of failure and returns 0 on success.
Example;-
#include<stdio.h>
int main()
{
FILE *fp;
fp = fopen("file1.txt","w");
fprintf(fp, "%s", "helloworld");
fclose(fp);
return 0;
}
Explanation:-
The above example will create a file called file1.txt.
The w means that the file is being opened for writing, and if the file does not exist then the new file will be created.
The fprintf function writes helloworld to the file.
The fclose function closes the file and releases the memory stream.
Comments
Post a Comment