The function of fscanf and scanf are exactly same only change is that scanf is used to get data input from keyboard where fscanf is used to get data from the file pointed to by fp because input is read from the file .
Program of read from keyboard and write into file.
#include<stdio.h>
#include<stdlib.h>
void main()
{
FILE *fp;
int n;
fp=fopen(“input.txt”,”w”); // open the file in write mode
if(fp==NULL)
{
printf(“error in opening the file”);
exit();
}
while(scanf(“%d”,&n)!=EOF)
{
fprintf(fp,”%d”,n);
}
fclose(fp);
}