2
#include<stdio.h>
void selsort(int a[],int s)
{
int min,temp,i,j;
for(i = 0; i < s ; i++)
{
min = 0;
for(j = i+1 ; j < s; j++)
{
if(min > a[j])
{
min = j;
}
}
temp = a[i];
a[i] = a[min];
a[min] = temp;
for (j=0;j<s;j++)
{
printf("%d",a[i]);
}
printf("\n");
}
}
main()
{
int i,a[5];
int size = 5;
printf("Enter elements of the array");
for(i=0;i<size;i++)
{
scanf("%d",&a[i]);
}
selsort(a[5],size);
}
錯誤如下:C:分段故障(選擇排序)
selsort.c:35:2: warning: passing argument 1 of ‘selsort’ makes pointer from integer without a cast [enabled by default]
selsort.c:2:1: note: expected ‘int *’ but argument is of type ‘int’
如何避免在將來出現此問題將是非常有幫助的任何提示
非常感謝,這真的很有用:) – user1905568
@ user1905568歡迎您!如果您的問題解決了,您可能希望通過點擊複選標記來接受答案,以表明您不再尋找改進的答案,並在堆棧溢出時獲得全新的徽章。 – dasblinkenlight