Hello, I am new to file pointers. All I have to do is copy the values from one file (a1.txt), add 50 to each of the numbers and save it to another file (a2.txt)
a1.txt looks like:
11
12
13
....
25
a2.txt should look like:
61
62
63
...
75
The problem is fscanf is picking up only 1 instead of 11 in the first line of a1.txt and so 51 is getting printed instead of 61 in a2.txt. However, it is working fine for the subsequent lines. I am unable to figure out the problem...Kindly help...
here is the code:
Code:#include<stdio.h> void main(){ FILE *fp1,*fp; int i; char ch; fp=fopen("a1.txt","r"); fp1=fopen("a2.txt","w"); while (1) { ch = fgetc( fp ) ; if(ch==EOF) break; fscanf(fp,"%d",&i); fprintf(fp1,"%d\n",i+50); } }



3Likes
LinkBack URL
About LinkBacks



..but thanks nevertheless for the explanations...got the point ! 
