I'm trying to initialize array bucket in bucketSort using size to initialize the size of the array. But my compiler is saying
6.31.c:19: error: storage class specified for parameter `size'
6.31.c: In function `bucketSort':
6.31.c:21: error: variable-sized object may not be initialized
6.31.c:21: warning: excess elements in array initializer
6.31.c:21: warning: (near initialization for `bucket[0]')
How do I do this?
Code:
#include <stdio.h>
void bucketSort(int[], int size);
int main()
{
int numbers[ 8 ] = { 9 };
bucketSort( numbers, 8 );
return 0;
}
void bucketSort(int array[], int size)
{
int bucket[ 10 ][ size ] = { 0 };
int i, j, n;
for (i = 0; i <= size - 1; ++i) {
j = 0;
while ( bucket[ (array[ i ] % (n * 10) ) / 10 ][ j ] != array[ i ] ) {
if ( bucket[ (array[ i ] % (n * 10) ) / 10 ][ j ] == -1)
bucket[ (array[ i ] % (n * 10) ) / 10 ][ j ] = array[ i ];
else
++j;
}
}
}