I am attempting to write a C program which reads input from a text file and puts it into a 2D-array where Rows are lines and columns are characters.
However I am confused after reading the following article:
http://c-faq.com/aryptr/pass2dary.html
The function definition which I am thinking of is
int processArray(char **text) {
...
...
}
where I am attempting to pass in a pointer to a 2D array whose dimensions I don't know until runtime. I would like to be able to access the elements using two square brackets [] []
However in the link it says the following:
An intermediate pointer would have to be used when attempting to call it with a two-dimensional array:
extern g(int **ipp); int *ip = &array[0][0]; g(&ip); /* PROBABLY WRONG */
but this usage is misleading and almost certainly incorrect, since the array has been ``flattened'' (its shape has been lost).
- What is wrong with the above declaration?
- How should you define an array to multiple dimensions?