我的程序应该排列由用户输入的数字列表,但它在到达第一个printf之前崩溃。我的编译器发出2个警告,但我没有看到问题。我还没有学习过指针,所以我不想使用它们。下面是消息:我的程序崩溃了,我不明白为什么它甚至没有达到第一个printf
在功能`selection_sort ':
[Warning] passing arg 2 of `selection_sort' makes pointer from integer without a cast
在函数'主':
[Warning] passing arg 2 of `selection_sort' makes pointer from integer without a cast
。
#include<stdio.h>
int selection_sort(int n, int v[n])
{
int high = v[0];
int i;
for(i = 0; i < n; i++)
high = high < v[i]? v[i] : high;
if(n - 1 == 0)
return;
v[n - 1] = high;
n -= 1;
selection_sort(n, v[n]);
}
int main(void)
{
int n, i;
int v[n];
printf("Enter how many numbers are to be sorted: ");
scanf("%d", &n);
printf("Enter numbers to be sorted: ");
for(i = 0; i < n; i++)
scanf("%d", &v[i]);
selection_sort(n, v[n]);
printf("In crescent order: ");
for(i = 0; i < n; i++)
printf("%d ", v[i]);
getch();
return 0;
}
如果你看到'INT v [N];',你怎么看它? – Gabe
@Gabe的后续行动:请注意,在那一点上,n没有任何价值。 –
我认为它宣布了一个数组。这是错的吗? – user3091996