/ ************************************************************************ * * 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: 2024/8/14 19:12,
18.216.91.156:LOG IN
|
©2024 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? <A HREF="http://piclist.com/techref/language/ccpp/cref/EXAMPLES/bsearch.c"> language ccpp cref EXAMPLES bsearch</A> |
Did you find what you needed? |
![]() o List host: MIT, Site host massmind.org, Top posters @none found - 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: Gregg Rew. on-going support is MOST appreciated! * Contributors: Richard Seriani, Sr. |
Welcome to piclist.com! |
.