I would like to run this to see if it works. It is supposed to sort an table of integers, but I don't know how the main function is supossed to look like. How do I enter *tab into the function?
void swap(int *a, int *b)
{
int buffer;
buffer = *a;
*a = *b;
*b = buffer;
}
sort_int_tab(int *tab, int size)
{
int a;
int z;
z = 0;
while(z < size)
{
a = 1;
while(a < size)
{
if(tab[z] >= tab[a])
{
swap(&tab[z], &tab[a]);
}
z++;
}
} a++;
z++;
}
int main(void)
{
sort_int_tab();
return ();
}
There are two important issues in your code. First, your function does not have a return type. Since you are not returning anything, it should be void
:
void sort_int_tab(int *tab, int size) {
/// Your code...
}
Second, inside of main, you are calling the function without arguments. You should pass an array of int (remember to allocate memory and initialise it), and the size of the array:
sort_int_tab(tab, size);
You can initialize an array like this and then pass it to your function:
int tab [5] = { 3, 4, 1, 2, 5};
sort_int_tab(tab, 5);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.