Hi!
I'm just starting to code in C, and I'm trying to read the information in a dat file, to then use it in some calculations. I read the information in the file and then save it in an array. However when I try later to access that array I only get zeros. I've checked that the code is indeed reading the values, but I don't know what to do to actually save them. I appreciate any input you can give me about it!
This is the section of the code that reads the dat file:
/* Open the file */
fp = fopen("VELOCITY_nodes.dat", "r");
/*file=fopen("VELOCITY_nodes.dat", "r");*/
/* Check that the file is open */
if (fp==NULL){
Message("ERROR: cannot open the velocity file");
}
else
{
/* Now that the file is open, loop until */
/* the max of the data is reached */
while (i<=max)
{
/* Initialize j */
j=0;
/* Do only up to 2, because the positions of */
/* the velocity vecto are [0,1,2] */
while (j<=2)
{
fscanf(fp,"%f",&vel);
velxyz[i][j]=vel;
/* Print the positions (i,j) for the matrix */
Message("i=%d j=%d\n",i,j);
/* Print the velocity value read */
/* at this point I check that the values are read*/
Message("vel (i,j) = %f \n", velxyz[i][j]);
++j;
}
++i;
}
}
fclose(fp);
/*then here I try to read any position on the matrix velxyz, and there are only zeros */
Message("vel (i,j) = %f \n", velxyz[10][1]);