how to read the file into 2d array without knowing its size?
read from the file into a 2d array
Collapse
X
-
First, read this: http://bytes.com/topic/c/insights/77...rrays-revealed. Here you will learn that there really are not 2D arrays in C or C++.
Second, find out the format the file.
Third, count the numbers in the file.
Fourth, dynamically allocate memory to hold those numbers. That is, use malloc() if you write in C or the new operator if you write in C++.
Fifth, read the numbers from the file into your allocated memory
Sixth, create a pointer to an array[x][y] where y is the columns and x is the number of rows. Place the address of your allocation in this pointer.
Seventh, access your array only through this pointer. Your view will be a 2D array.
Comment