I have a dynamic 2D float array and a file with both strings, integers(number of floats in the line) and float numbers. I got the number of lines from the first line on the file and the number of columns from the highest of the integers in the line.
Example:
Code:Code:2 John 3 5.5 89.5 30.67 0.00 Mary 4 78.9 67.4 67.3 9.0 0.00 (null)
The number of lines is the one on the file + 1 because the last line is supposed to be empty and the number of columns is the highest of the integers after the names + 1 (5 in this case) because the 0.00 marks the end of each line. How do I load only the floats into memory?
I've tried different types of loops with fgets and strtok like
orCode:for(i = 0; i < num_lines; i++){ fgets(buf,1000, arq); fscanf(aux, "%s ", &name); fscanf(aux, "%d ", &col); for(j = 0; j < num_columns; j++){ fscanf(arq, "%f ", &M[i][j]); } }
Code:num = atof(strtok(NULL, " "));instead of the fscanf(arq, "%f ", &M[i][j]);Code:M[i][j] = num;
But it doesn't work, I get either an array full of 0.00 or -0.00 or at most random numbers between them. I need it to be an array of floats instead of strings because other functions will use the lines for math operations.