I'm first year student and I do C programming. Don't be so mean to me, please.
Could you show how to use and write multi-dimensional arrays in functions?
I have researched the arrays and function arg input.
I have read that the first dimension is not that important to the compiler. It checks the second and further dimensions in an array, so you have to specify it even in the function to make it work.
I tried different combinations for arrays to make it work but didn't find a solution.
There is a little piece of my code:
int size=5,location_x=10,location_y=10,s=NULL,l_x, l_y, status=2;
int stage_3(float[][int],int [],int [],int []);
int main()
{
float location[l_x][l_y];
int x[size], y[size], z[size];
if(!stage_3(location[l_x][l_y],x[size],y[size],z[size]))
return 0;
}
int stage_3(float location[][int l_y],int x[size],int y[size],int wt[size])
{
return 0;
}
13|error: expected expression before 'int'
13|error: expected ';', ',' or ')' before 'int'
I have idea that the problem are those [][]. They are not constants. The program makes them as variables that you could choose by scanf as you wish in accessible range for more flexibility.
malloc()and dynamically allocate the arrays, or you con do something likeint stage_3(size_t size, size_t l_y, float location[][l_y], int x[size], int y[size], int wt[size])malloc()it's difficult to get to understand how exactly pointers work and also, withmalloc()you must assume a new responsibility, tofree()themalloc()ed blocks.