Hi there, I'm trying to read an unknown number of data points from txt based file into a 2d array. The file contains a grid of numbers which has 4 columns and an unknown set of rows. To start with I read just the first 20 rows and it worked. I am now unsure of what the code would be to read the rows until there is no more data.
Any help would be much appreciatedCode:#include <stdio.h> #include <stdlib.h> int main() { FILE *myfile; int j,i; float c[20][4]; myfile = fopen("data.txt","r"); if(!myfile) { puts("data.TXT not found!"); exit(0); } j = 0; while (j<20) { i=0; while (i<4) { fscanf(myfile,"%f",&c[j][i]); printf("%.8f\n",c[j][i]); i=i+1; } j = j+1; } fclose(myfile); return 0; }



LinkBack URL
About LinkBacks



