/* * Binary Character Search. Given a sorted array of characters, find a given * character in the array. Returns 1 if the character is found, 0 if the * character is not found. * * key - character being looked up * list - sorted array of characters to search in * len - length of list, minus any trailing (not required) NULL */ static int bcsrch(char key, const char* list, unsigned int len) { char* base = list; char* last = base + len - 1; /* Last element in table */ char* p; while (last >= base) { p = base + ((last - base) >> 1); if (key == *p) return 1; /* Key found */ else if (key < *p) last = p - 1; else base = p + 1; } return 0; /* Key not found */ }