fclose() in c

The fclose() function is used for closing opened files. The only argument it accepts is the file pointer

Example of fclose() function

#include <stdio.h>
main ()
 FILE *fp;
 float total;
 fp = fopen("data.txt", "w+");
 if (fp == NULL) {
 printf("data.txt does not exist, please check!\n");
 exit (1);
fprintf(fp, 100);
 fscanf(fp, "%f", &total);
 printf("Value of total is %f\n", total);

Leave a Comment