I have a data file that contains the following information for radius, density, acceleration, and pressure:
1.464e+22 1.403e-25 1.290e-08 6.325-10
1.539e+22 1.394e-25 1.680e-08 6.309-10
1.616e+22 1.384e-25 2.030e-08 6.289e-10
1.693e+22 1.373e-25 2.344e-08 6.266e-10
1.769e+22 1.362e-25 2.628e-08 6.239e-10
How can I store this data in arrays (e.g., radius[], density[])? The code to read the data file is as follows:
#include"stdio.h"
#define NDATA 5
int main()
{
FILE *fo;
int i;
float r[NDATA];
float rho[NDATA];
float g[NDATA];
float p[NDATA];
fo = fopen("data.txt", "r");
/* Read data */
for (i = 0; i<NDATA; i++)
{
fscanf(fo, "%f %f %f %f", &r[i], &rho[i], &g[i], &p[i]);
printf(" read line %d %e %e %e %e\n", i, r[i], rho[i], g[i], p[i]);
}
}
This should work since you will not be reading in the first two lines and blank lines.