for( i = 0; i < sizeof(arr)/sizeof(arr[0]); ++i ) /* Output sorted list */
printf( "%s ", arr[i] );
/* Find the word "cat" using a binary search algorithm: */
result = (char **)bsearch( (char *) &key, (char *)arr, sizeof(arr)/sizeof(arr[0]),
sizeof( char * ), (int (*)(const void*, const void*))compare );
if( result )
printf( "\n%s found at %Fp\n", *result, result );
else
printf( "\nCat not found!\n" );
}
Sample Output
cat cow dog goat horse human pig rat
cat found at 002F0F04