And this is such a common problem that there is already a function in stdlib.h even for AVR.
Is there a "bsearch_P" ?