for( k=0; k < secnum; k++) {
if(arrayi[i][k] > arrayi[i][k+1] )
The length of
array[i]
is
secnum
. Therefore, the maximum index you can access is
secnum - 1
.
When your loop reaches the final iteration,
k = secnum - 1
, so you cannot access
arrayi[i][k + 1]
, because that is outside the bounds of the array.
(You could have easily found this out for yourself by using the debugger.)
Change your loop to:
for ( k=0; k < secnum - 1; k++) {