17.02.2015 Views

CCS C Compiler Manual PCB / PCM / PCH

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Examples:<br />

Example Files:<br />

Also See:<br />

brownout_enable(TRUE);<br />

None<br />

restart_cause()<br />

bsearch( )<br />

Syntax:<br />

Parameters:<br />

Returns:<br />

Function:<br />

Availability:<br />

Requires:<br />

Examples:<br />

ip = bsearch (&key, base, num, width, compare)<br />

key: Object to search for<br />

base: Pointer to array of search data<br />

num: Number of elements in search data<br />

width: Width of elements in search data<br />

compare: Function that compares two elements in search data<br />

bsearch returns a pointer to an occurrence of key in the array pointed to<br />

by base. If key is not found, the function returns NULL. If the array is not<br />

in order or contains duplicate records with identical keys, the result is<br />

unpredictable.<br />

Performs a binary search of a sorted array<br />

All devices<br />

#INCLUDE <br />

int nums[5]={1,2,3,4,5};<br />

int compar(const void *arg1,const void *arg2);<br />

void main() {<br />

int *ip, key;<br />

key = 3;<br />

ip = bsearch(&key, nums, 5, sizeof(int), compar);<br />

}<br />

int compar(const void *arg1,const void *arg2) {<br />

if ( * (int *) arg1 < ( * (int *) arg2) return –1<br />

else if ( * (int *) arg1 == ( * (int *) arg2) return 0<br />

else return 1;<br />

}<br />

Example Files:<br />

Also See:<br />

None<br />

qsort()<br />

164

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!