Function that takes as input a 3 dimensional array, and its dimensions
How can I do that
Code:void inputArray(int fd,int sd,int td,int array[fd][sd][td])
Function that takes as input a 3 dimensional array, and its dimensions
How can I do that
Code:void inputArray(int fd,int sd,int td,int array[fd][sd][td])
If I declare the function like that ,it gives me error that the variables are not declared
declare array size as a constant and try to post the full code if possible
I am trying to define function that takes as input a 3 dimensional array, and its dimensions
Code:#include <stdio.h> #define fd 5 #define sd 5 #define td 5 void inputArray(int fd,int sd,int td,int array[fd][sd][td]); int main() { getchar(); return 0; } void inputArray(int fd,int sd,int td,int array[fd][sd][td]) { }
You need to name your integer parameters and your array sizes differently.
Your code expands to something like
void inputArray(int 5,int 5,int 5,int array[5][5][5]);
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.
Thanks
I am trying to pass to the function array defined by the user ,how can I do that
If you have
int array[10][20][30];
Then the prototype/definition of the function would look like this
void func ( int array[10][20][30] );
It might also look like this, without changing anything else.
void func ( int array[][20][30] );
void func ( int (*array)[20][30] );
Since it is only the left-most dimension which can vary (all the others have a fixed size for a given multi-dimensional array), you only need pass the length of the array in it's left-most dimension.
So perhaps it becomes
void func ( int array[10][20][30], size_t len );
Calling this function is easy
func( array, 10 );
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.
Or you can just pass a pointer, hoping that the user has defined or allocated the 3d array correctly...
Devoted my life to programming...
Thanks