fscanf() and fprintf() function in c

The functions fprintf() and fscanf() are similar to printf() and scanf() except that these functions operate on files and require one additional and first argument to be a file pointer

Example of fscanf() and fprintf() 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);
 fclose(fp);
 printf("Value of total is %f\n", total);
}

Leave a Comment