Read formatted data from a stream: how to use fscanf
#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;
}
Related examples in the same category