여기 내 코드가 있습니다. 어떤 이유로 인해 부호없는 long을 사용해야합니다. gdb는 내가 seg fault라는 것을 알려줍니다. 누가 나를 도울 수 있습니까? 나는 혼자서 그것을 발견 할 수 없었다. 가장 흥미로운 점은 유형을 부호없는 long에서 int로 변경하면 seg 오류가 없다는 것입니다.내 계산 종류에 seg 오류가 있습니다.
코드는 여기에 있습니다 :
#include <stdio.h>
int counting_Sort (unsigned long ary[], unsigned long array_size,unsigned long max){
unsigned long counting[max+1];
unsigned long j;
for(j=0;j<max+1;j++){
counting[j]=0;//initize to zero
}
unsigned long i;
for(i=0;i<array_size;i++){
counting[ary[i]]++;
}
unsigned long q;
for(q=1;q<max+1;q++){
counting[q]=counting[q-1]+counting[q];
}
for(q=0;q<max+1;q++){
counting[q]=counting[q]-1;
}
unsigned long outputAry[array_size];
unsigned long d;
for(d=(array_size-1); d>=0;d--){
outputAry[counting[ary[d]]]=ary[d];// SEG FAULT IS HERE
counting[ary[d]]--;//AND HERE
}
unsigned long m;
//for(m=0; m<array_size;m++){
// printf("%lu\n",outputAry[m]);
// }
return 0;
}
int main(){
unsigned long array[7]={2,6,4,0,1,7,9};
printf("before sorting the order is: \n");
unsigned long i;
for(i=0;i<7;i++){
printf("%lu\n",array[i]);
}
printf("after sorting, the new order is: \n");
counting_Sort(array,7,9);
getchar();
return 0;
}
1. 종종 사용자가 디버거를 사용하는 것이 아니라 추측하여 디버그하려고하는 것을 보았습니다. –
[최소 완성 예제] (http://stackoverflow.com/help/mcve)를 준비하는 방법을 배우면 앞설 것입니다. – Beta