Take out this line from the end of the function:
checked = 1;
And replace it with this:
Then, look at your code - it's not the check that is wrong now, it's the init_array.
init_array(arr, 20, 1, 15);
int x = check_array(arr, 20);
Run you app and look at what you get printed:
Is all you get.
So, why doesn't it exit from init_complete?
Simple: it never gets out of your
loop, so i never gets increased. And because the array is initialized to zeros, it will automatically find a match every time it tries to check ...
Have a look with the debugger and see if you can see what I mean.