Mega Code Archive

 
Categories / C / File
 

Read formatted data from a stream

#include <stdio.h> int main () {   char str[80];   float f;   FILE *file;   file = fopen ("my.txt","w+");   fprintf (file, "%f %s", 3.14, "PI");   rewind (file);   fscanf (file, "%f", &f);   fscanf (file, "%s", str);   fclose (file);   printf (" %f and %s  are added. \n",f,str);   return 0; }