Hi everyone - can someone pls help me with this issue i am having with reading a file -
I am trying to read a file of 5 columns of data - and then i have to analyse the 3rd, 4th and 5th column.
The data looks like this - (its all clustered together below - but the first row is = 1....1....14.027...3.474....1.964 etc etc)
1 1 14.027 3.474 1.964
1 2 13.936 3.445 1.967
1 3 14.055 3.457 1.875
1 4 14.019 3.468 1.953
2 5 15.084 2.893 4.812
2 6 15.158 2.912 4.870
2 7 15.107 2.935 4.729
This is the program I am using to read the file and save the 3rd. 4th and 5th in arrays called x, y and z
Code:#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
main (int argc, char **argv)
{
int i, j, p, q, count, d[20];
double a, b, c, r[20];
double x[3492][4], y[3492][4], z[3492][4];
FILE *fp;
fp = fopen ("1.gro", "r");
for (i=0; i<3492; i++)
for (j=0; j<4; j++)
{
if (j==0 || j==3)
fscanf(fp, "%5.6d%5.2d%lf___%lf___%lf", p, q, &x[i][j], &y[i][j], &z[i][j]);
if (j==1 || j==2)
fscanf(fp, "%5.5d%5.2d%lf___%lf___%lf", p, q, &x[i][j], &y[i][j], &z[i][j]);
}
.
.
.
fclose(fp);
return 0;
}
However when i print out what i read in as x[i] [j] and y[i] [j] and z[i] [j] - whether on screen or in a new file, i get lots of -
325534197301 -1.6f_0.000000_0.000000
3255341973014197510.6f_0.000000_0.000000
3255341973014197510.6f_0.000000_0.000000
3255341973014197484.6f_0.000000_0.000000
Can someone pls explain what I was doing wrong - thanks a lot.