beautypg.com

Rand – Zilog EZ80F916 User Manual

Page 377

background image

UM014423-0607

C Standard Library

ZiLOG Developer Studio II

eZ80Acclaim!

®

User Manual

357

The array is sorted in ascending order according to a comparison function pointed to by

compar

, which is called with two arguments that point to the objects being compared. The

compar

function returns an integer less than, equal to, or greater than zero if the first argu-

ment is considered to be respectively less than, equal to, or greater than the second.

If two members in the array compare as equal, their order in the sorted array is unspeci-
fied.

Synopsis

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

Example

int lst[]={5,8,2,9};
int compare (void * x, void * y);
qsort (lst, sizeof(int), 4, 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;

}

rand

Computes a sequence of pseudorandom integers in the range 0 to RAND_MAX.

Synopsis

#include
int rand(void);

Returns

A pseudorandom integer.

Example

int i;
srand(1001);
i=rand();

This manual is related to the following products: