aboutsummaryrefslogblamecommitdiff
path: root/6.1.1/key.c
blob: f6384fe472fe2b325e9d88264e24754977863cec (plain) (tree)






















                                                         
#include <string.h>
#include "key.h"

struct key *
bsearch(char *word, struct key tab[], int n)
{
	int cond;
	struct key *low, *high, *mid;

	low = tab;
	high = tab + n - 1;
	while (low <= high) {
		mid = low + (high-low) / 2;
		if ((cond = strcmp(word, mid->word)) < 0)
			high = mid - 1;
		else if (cond > 0)
			low = mid + 1;
		else 
			return mid;
	}

	return NULL;
}