fprint and fscanf

these functions are used in file handling ,this is similar to the actual functions printf and scanf .when the file is created first ,these functions will run in the file .fprintf and fscanf excepts a pointer to the structure FILE

example for writing a file

#include
#include
main()
{
FILE *doc;
doc = fopen("E://CODE45.TXT","w");
if (doc == NULL)
{
printf("error");
exit(1);
}
printf("enter number ");
int x;
scanf("%d",&x);
fprintf(doc,"%d",x);
fclose(doc);
}

how lets print the same number using file mode r

#include
#include
main()
{
FILE *doc;
doc = fopen("E://CODE45.TXT","r");
if (doc == NULL)
{
printf("error");
exit(1);
}
int x;
fscanf(doc,"%d",&x);
printf("Value of n=%d",x);
fclose(doc);
return 0;
}