I cant find out how it's the syntax.
func(int [][] a) doesnt work... any hint?
Thanks!
I cant find out how it's the syntax.
func(int [][] a) doesnt work... any hint?
Thanks!
For multidimensional arrays I believe you have to specify the size in the function declaration and implementation (maybe not in the declaration?).
These sum up simple arrays and multidimensional arrays:
http://www.cogs.susx.ac.uk/users/pet...ml/node26.html
http://www.cogs.susx.ac.uk/users/pet...ml/node27.html
No No's:
fflush (stdin); gets (); void main ();
Goodies:
Example of fgets (); The FAQ, C/C++ Reference
My Gear:
OS - Windows XP
IDE - MS Visual C++ 2008 Express Edition
ASCII stupid question, get a stupid ANSI
Thanks, checking now.
If you know the size at compile time, you specify the size (although the first dimension isn't necessary). If you don't know the size, or the array is dynamically allocated, you should use a vector instead. Otherwise you'll have to pass the size as an extra function parameter and pass the array by pointer.
In C/C++, you have to put array indicies ([]) after the variable name, unlike in Java where you can put them before or after. And of course, as mentioned, all but the leftmost index must have sizes in them.Code:func(int [][] a)
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
> func(int [][] a) doesnt work... any hint?
Copy / paste works
If your array is
int arr[X][Y][Z];
Then the function can(*) be written as
void func ( int arr[X][Y][Z] );
And you would call it with
func( arr );
(*) Some compilers will warn you about the redundant major dimension (the left-most one), so you can easily change it to
void func ( int arr[ ][Y][Z] );
If you want to spend extra effort, you can write it like this if you want
void func ( int (*arr)[Y][Z] );
All 3 forms are equivalent.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.