S
shekharpati
hi all,
I,m trying to read a space delimited file with the use of formated
input through fscanf. But surprisingly i am able to read all the 4999
lines of data except the "first line" which is giving random output(i.e
not present in the file). the code is given below(the relevant part).
sample input from the data file
01 48554.73828 504 30.48.37.001953 76.15.33.632813
2 48554.67969 504 30.48.36.722168 76.15.33.527344
3 48554.63281 504 30.48.36.442383 76.15.33.421875
4 48554.58594 504 30.48.36.162598 76.15.33.316406
5 48554.54297 504 30.48.35.882813 76.15.33.210938
the output(the first line)
18001844.273438 135633.742190 44.273438 30 5000 14
2 48554.67969 504 30.48.36.722168 76.15.33.527344
3 48554.63281 504 30.48.36.442383 76.15.33.421875
4 48554.58594 504 30.48.36.162598 76.15.33.316406
5 48554.54297 504 30.48.35.882813 76.15.33.210938
I got this prob before when i was only reading the first two columns
but as you might have noticed the leading '0' before 1 solved it.
Surprisingly i can still read the first two columns correctly but the
later ones are the ones that get of of hand. That too only in the first
line. rest 4999 lines are read just fine. I cannot figure it out. plz
help.its important
shashank
(i am using borland c++ 5.5, win2000)
_______________________________
fp=fopen ("TEMP31.TXT","r");
if (fp==NULL)
{ puts("cannot open file");exit(1);
}
while ((fgetc(fp))!=EOF)
{
fscanf(fp,"%d%lf%d%d.%d.%lf%d.%d.%lf",&x[a],&y[a],&fl_h[a],&latdeg[a],&latmin[a],&latsec[a],&longdeg[a],
&longmin[a],&longsec[a]);
printf ("\n%d %lf %d %d %lf %d %d %lf
%d",x[a],y[a],latdeg[a],latmin[a],latsec[a],longdeg[a],longmin[a],longsec[a],fl_h[a]);//(here
when i print it gives the correct values)
if ((a%100)==0) {getch();} else{}
a=a+1;
}
fclose(fp);
getch();
for (i=0;i<AR;i++)
{
lat=(latsec+(latmin*60)+(latdeg*3600));
lon=(longsec+(longmin*60)+(longdeg*3600));
printf ("\n%lf %lf %lf %d %d
%d",lat,lon,latsec,latmin,latdeg,fl_h);// from here
on i get junk value
if ((i%100)==0) {getch();} else{}
}
getch();
_______________________________
this is the starting code i.e the code before the above given prog
segment, the initialisations and all (though i dont think it will be
neccessary but just to be sure)
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
#define ARRAY 5000
#define AR 4999
#define PI 3.142857
#define CONV 30.8333
main()
{
clrscr();
FILE *fp;
static int
x[AR],latdeg[AR],latmin[AR],longdeg[AR],longmin[AR],fl_h[AR];
static double
y[AR],longsec[AR],latsec[AR],lat_p[100],long_p[100],lat_m[100];
static double
long_m[100],lat[AR],lon[AR],dist_p[100],dist_m[100],p[100],m[100],hp[100],
hm[100],lata,longa,latb,longb,latp,longp,latm,longm,dist_f,dist_i,pa,t,ta,tta,tta1,ttta,ttta1;
int a=0,b=0,c=0,d=0,e=0,ca=0,da=0,f=0,g=0,i,j,z,sl=0,sl1=0;
double
sa=0.0,sa1=0,sb=0.0,sc=0.0,sd=0.0,se=0,sf=0,sg=0,sg1=0,sh=0,sh1=0,xa=0,xb=0,xp=0,xm=0,ya,yb,yp=0,ym=0;
static float fl_p[100],fl_m[100],fl_hp,fl_hm,fl_ha,fl_hb;
_________________***********_______________
I,m trying to read a space delimited file with the use of formated
input through fscanf. But surprisingly i am able to read all the 4999
lines of data except the "first line" which is giving random output(i.e
not present in the file). the code is given below(the relevant part).
sample input from the data file
01 48554.73828 504 30.48.37.001953 76.15.33.632813
2 48554.67969 504 30.48.36.722168 76.15.33.527344
3 48554.63281 504 30.48.36.442383 76.15.33.421875
4 48554.58594 504 30.48.36.162598 76.15.33.316406
5 48554.54297 504 30.48.35.882813 76.15.33.210938
the output(the first line)
18001844.273438 135633.742190 44.273438 30 5000 14
2 48554.67969 504 30.48.36.722168 76.15.33.527344
3 48554.63281 504 30.48.36.442383 76.15.33.421875
4 48554.58594 504 30.48.36.162598 76.15.33.316406
5 48554.54297 504 30.48.35.882813 76.15.33.210938
I got this prob before when i was only reading the first two columns
but as you might have noticed the leading '0' before 1 solved it.
Surprisingly i can still read the first two columns correctly but the
later ones are the ones that get of of hand. That too only in the first
line. rest 4999 lines are read just fine. I cannot figure it out. plz
help.its important
shashank
(i am using borland c++ 5.5, win2000)
_______________________________
fp=fopen ("TEMP31.TXT","r");
if (fp==NULL)
{ puts("cannot open file");exit(1);
}
while ((fgetc(fp))!=EOF)
{
fscanf(fp,"%d%lf%d%d.%d.%lf%d.%d.%lf",&x[a],&y[a],&fl_h[a],&latdeg[a],&latmin[a],&latsec[a],&longdeg[a],
&longmin[a],&longsec[a]);
printf ("\n%d %lf %d %d %lf %d %d %lf
%d",x[a],y[a],latdeg[a],latmin[a],latsec[a],longdeg[a],longmin[a],longsec[a],fl_h[a]);//(here
when i print it gives the correct values)
if ((a%100)==0) {getch();} else{}
a=a+1;
}
fclose(fp);
getch();
for (i=0;i<AR;i++)
{
lat=(latsec+(latmin*60)+(latdeg*3600));
lon=(longsec+(longmin*60)+(longdeg*3600));
printf ("\n%lf %lf %lf %d %d
%d",lat,lon,latsec,latmin,latdeg,fl_h);// from here
on i get junk value
if ((i%100)==0) {getch();} else{}
}
getch();
_______________________________
this is the starting code i.e the code before the above given prog
segment, the initialisations and all (though i dont think it will be
neccessary but just to be sure)
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
#define ARRAY 5000
#define AR 4999
#define PI 3.142857
#define CONV 30.8333
main()
{
clrscr();
FILE *fp;
static int
x[AR],latdeg[AR],latmin[AR],longdeg[AR],longmin[AR],fl_h[AR];
static double
y[AR],longsec[AR],latsec[AR],lat_p[100],long_p[100],lat_m[100];
static double
long_m[100],lat[AR],lon[AR],dist_p[100],dist_m[100],p[100],m[100],hp[100],
hm[100],lata,longa,latb,longb,latp,longp,latm,longm,dist_f,dist_i,pa,t,ta,tta,tta1,ttta,ttta1;
int a=0,b=0,c=0,d=0,e=0,ca=0,da=0,f=0,g=0,i,j,z,sl=0,sl1=0;
double
sa=0.0,sa1=0,sb=0.0,sc=0.0,sd=0.0,se=0,sf=0,sg=0,sg1=0,sh=0,sh1=0,xa=0,xb=0,xp=0,xm=0,ya,yb,yp=0,ym=0;
static float fl_p[100],fl_m[100],fl_hp,fl_hm,fl_ha,fl_hb;
_________________***********_______________