please dont rip this site

language ccpp CREF EXAMPLES bsearch

/ ************************************************************************
 *
 * Purpose: To demonstrate the 'bsearch' function.
 *
 * Author:  M.J. Leslie
 *
 * Date:    04-Jun-95
 *
 ************************************************************************/

#include <stdlib.h>

#define NUM 11

static int func (void *, void *);

/************************************************************************/

main()
{
					/* List of numbers.		*/
  int numbers[NUM]={3,4,7,9,11,13,15,17,19,21,23};
  int key=22;				/* number to find.		*/
  int * result;			/* Result of 'bsearch'		*/

					/* Search for 'key' in 'numbers'*/

  result = bsearch (&key, numbers, NUM, sizeof(numbers[0]), (void *)func);

  printf("%d ", key);
  (result) ? puts("found") : puts("not found"); 
}

/************************************************************************/

static int func (void *a, void *b)
{
  printf("%d %d \n", *(int *)a, *(int *)b);	/* Diagnistics.		*/

					/* Compare the two numbers	*/
  if (*(int *)a == *(int *)b) return(0);
  if (*(int *)a <  *(int *)b) return(-1);
  return (1);
}


file: /Techref/language/ccpp/CREF/EXAMPLES/bsearch.c, 1KB, , updated: 1997/4/21 09:52, local time: 2012/5/25 07:20,
TOP NEW HELP FIND: 
38.107.179.234:LOG IN

 ©2012 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE! / 

<A HREF="http://www.piclist.com/techref/language/ccpp/CREF/EXAMPLES/bsearch.c"> language ccpp CREF EXAMPLES bsearch</A>

Did you find what you needed?

  PICList 2012 contributors:
o List host: MIT, Site host massmind.org, Top posters @20120525 RussellMc, IVP, alan.b.pearce, cdb, V G, Isaac Marino Bavaresco, Electron, John Gardner, Carl Denk, Dwayne Reid,
* Page Editors: James Newton, David Cary, and YOU!
* Roman Black of Black Robotics donates from sales of Linistep stepper controller kits.
* Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters.
* Monthly Subscribers: None at this time. on-going support is MOST appreciated!
* Contributors: Richard Seriani, Sr.
  'What can I do?' - SiCKO

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .