-
Read a 2D array
I need to make a matrix[i][j] in C which will read from a file with the format bellow:
1,3.567,4.893,1.756
2,7.875,8.872,4.438
3,8.234,9.987,3.908
.
.
.
so as the matrix[0][0]=1, matrix[0][2]=4.893, matrix[2][1]=8.234 and so on ...
can anyone help me in how to allocate memory and read the file
Thanks
-
Do you KNOW that you always have three columns?
If so, you could use realloc on a float/double [3] array.
--
Mats
-
The num of rows and columns will be different
-
Then you need some way of determining how many columns there are, and use a 2D dynamic array - common question here, so search the forum for an answer. It's certainly a lot easier to solve this sort of problem if you know a max size that it may be, but I also understand that this is not always feasible.
--
Mats