home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a120 / 1.ddi / WATCOM_C / WAT21.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-14  |  871 b   |  33 lines

  1. /*------------------------------------------------------------------*/
  2. /* ╡{ªí└╔ªW║┘: wat21.c                                              */
  3. /*------------------------------------------------------------------*/
  4.  #include <stdlib.h>
  5.  #include <stdio.h>
  6.  
  7.  #define NUM_ELEMS(array) (sizeof(array) / sizeof(array[0]))
  8.  
  9.  int mynumber[] = {222, 432, 678, 444, 920, 745};
  10.  
  11.  int numeric (const int *p1, const int *p2)
  12.  {
  13.     return(*p1 - *p2);
  14.  }
  15.  
  16.  int keyword_search(int key)
  17.  {
  18.     int *itemptr;
  19.  
  20.     itemptr = bsearch (&key, mynumber, NUM_ELEMS(mynumber),
  21.              sizeof(int), (int(*)(const void *,const void *))numeric);
  22.     return (itemptr - mynumber + 1);
  23.   }
  24.   void main()
  25.   {
  26.    int pos;
  27.    pos = keyword_search(678);
  28.    if(pos)
  29.      printf("678 ª∞⌐≤░}ªCñññº▓─ %d ¡╙ñ╕»└ª∞╕m.\n",pos);
  30.    else
  31.      printf("678 ñúªb░}ªCññ.\n");
  32.   }
  33.