I did not look too closely, but I think that the pseudo-code of the book uses unidirectional indexing, and for encoding in C (or most modern languages) you need to configure it to index with zero value.
The main suspect
for(int j=2; j<input; j++)
If you want to start with 1 instead of 2.
Termination condition
while(i>0 && A[i]>key)
You may also need to change it so that you are above -1, not 0.
EDIT:
After a little closer look, I'm sure you also need to tweak this while .
In addition, you should, of course, look at all the upper limits for similar questions separately.
source share