If j is equal to max+1, array[j] will cause a seg fault. But you should stick to what I told you and search the boards. This question has been answered a million times already.