I'm tring to code a C code that sorts the args given from the smallest to the largest, but I keep getting this error :
warning: assignment to ‘int’ from ‘int *’ makes integer from pointer without a cast [-Wint-conversion] 80 | array[x] = av[i];
I tried to change "int array[x];" to "int *array[x];" but I get another error because of this line -> gnome_sort(array, size);
Can someone help me with this? Thx
void gnome_sort(int *array, int size)
{
int tmp;
for (int i = 1; i < size;) {
if (array[i-1] <= array[i])
++i;
else {
tmp = array[i];
array[i] = array[i-1];
array[i-1] = tmp;
--i;
if (i == 0)
i = 1;
}
}
}
int main(int ac, char **av)
{
int i;
int x = 0;
int array[ac];
x = 0;
for (i = 1; av[i] != NULL; i++) {
array[x] = atoi(av[i]);
x++;
}
size_t size = sizeof(array)/sizeof(array[0]);
for (i = 0; i < size; i++)
gnome_sort(array, size);
for (i = 0; i < size; ++i)
printf("%d ", array[i]);
return 0;
}
main(int ac, int **av)is wrong among other things.array[x] = av[i];this line is wrong.arrayis an array of integers whileavis an array of pointers tochar.array[x] = atoi(av[i]);