beautypg.com

Calloc – Zilog EZ80F916 User Manual

Page 357

background image

UM014423-0607

C Standard Library

ZiLOG Developer Studio II

eZ80Acclaim!

®

User Manual

337

than zero if the first argument is considered to be respectively less than, equal to, or
greater than the second.

Synopsis

#include
void *bsearch(void *key, void *base, size_t nmemb, size_t size, int
(*compar)(void *, void *));

Returns

A pointer to the matching member of the array or a null pointer, if no match is found.

Example

#include
int list[]={2,5,8,9};
int k=8;

int compare (void * x, void * y);
int main(void)
{

int *result;
result = bsearch(&k, list, 4, sizeof(int), compare);

}

int compare (void * x, void * y)
{

int a = *(int *) x;
int b = *(int *) y;
if (a < b) return -1;
if (a == b)return 0;
return 1;

}

calloc

Allocates space for an array of nmemb objects, each of whose size is

size

. The space is

initialized to all bits zero.

Synopsis

#include
void *calloc(size_t nmemb, size_t size);

Returns

A pointer to the start (lowest byte address) of the allocated space. If the space cannot be
allocated, or if nmemb or

size

is zero, the

calloc

function returns a null pointer.

This manual is related to the following products: