arrays - Reading large amounts of number from a text file in C -
i trying read large amount of numerical data (doubles) text file. text file has 10 columns, each 242 numbers listed in it. columns separated spaces. trying take first , seventh columns , put them array. trying this:
int i; double a; double b; double junk; double array[2][242] file *fp; fp = fopen("data_table.dat", "w"); (i = 0; <= 242; i++); { fscanf(fp, "%f %f %f %f %f %f %f %f %f %f\n", a, junk, junk, junk, junk, junk, b, junk, junk, junk); array[0][i] = a; array[1][i] = b; } fclose(fp);
the thought had open text file, read 1 row of doubles , save first column , seventh column array, rest of them being junk. when examine array afterwards every single entry in array 6.943e-310, not close of data in data table.
another thing might worth noting after run entire text file empty. can fill again values after run code empty again. first entry in each column string of data in column (for example first column starts of length in nm).
you opened file writing "w" option in fp = fopen("data_table.dat", "w");
you want open reading instead "r" otherwise truncates file, why see nothing in afterwards.
Comments
Post a Comment