0
Segfault on C radix sorting algorithm
I keep getting a segmentation fault (timeout?) error when compiling this code in C. Can anyone help me find where is the error? I don't think I'm accessing any forbidden memory addresses, but who knows. https://code.sololearn.com/ceWZEBf2Rmj2/?ref=app
2 odpowiedzi
+ 1
In loop,
count[arr[i]%(pos*10)]++;
This lead to index out of range,
You declared count size as 10 maximum.
You have array values greater than 10
So when greater than 10, for example 634, if pos =10,
Then, 634%100=34
count[34] is array index out of bounds so raise segmentation error...
0
thanks, it's fixed! I'd forgotten to deal with the characters after the current digit so was getting multiple digit numbers. a simple division took care of that.