I am not getting all numbers but only last number while readind data from file.
And it has to be done with fscanf function.
/* input n nunbers fom user and write it in the file.find it's sum
and write the ans. in another file */
#include <stdio.h>
#include <conio.h>
void main()
{
int i,n,no,sum=0;
FILE *fp,*fs;
fp=fopen("d:\\tc\\bin\\strtNo.txt","w");
printf("%s","Enter value for n : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n Enter the no : ");
scanf("%d",&no);
fprintf(fp,"%d\n",no);
sum+=no;
}
fprintf(fp,"%d\n",99);
fclose(fp);
fs=fopen("d:\\tc\\bin\\strtSum.txt","w");
fprintf(fs,"%d",sum);
fclose(fs);
fp=fopen("d:\\tc\\bin\\strtNo.txt","r");
if(fp==NULL)
{
printf("ERROR");
}
while((fscanf(fp,"%d\n",no))!=99)
{
printf("%d\n",no);
}
fclose(fp);
getch();
}