I am trying to sort a multidimensional array with bubblesort. When i try to commit the array to my bubblesort function i get several errors:
bubblesort(lottozahlen[12] [6], k);
void bubblesort(int *array [12] [6], int length)
{
int i, j, k;
for (k=0; k<12; k++)
{
for (i = 0; i < length -1; ++i)
{
for (j = 0; j < length - i - 1; ++j)
{
if (array [k] [j] > array [k] [j + 1])
{
int tmp = array[k] [j];
array[k] [j] = array[k] [j + 1];
array [k] [j + 1] = tmp;
}
}
}
}
}
The errors are :
[Error] invalid conversion from 'int*' to 'int' [-fpermissive]
[Error] invalid conversion from 'int' to 'int*' [-fpermissive]
[Error] invalid conversion from 'int' to 'int* (*)[6]' [-fpermissive]
[Error] initializing argument 1 of 'void bubblesort(int* (*)[6], int)' [-fpermissive]
Thank you in advance!
Assuming lottozahlen
is declared as int lottozahlen[12][6]
:
void bubblesort(int *array [12] [6], int length)
here the array
parameter is declared as an array of array of pointers. Not what you want.
bubblesort(lottozahlen[12] [6], k);
here you call bubblesort
with the element of the array at position (12, 6)
as the first argument. Not want you want either.
It should be:
bubblesort(lottozahlen, k);
void bubblesort(int array [12] [6], int length)