Standard Library Functions
Returns a pseudo random integer in the range 0..RAND_MAX (limits.h) which is at
void srand(unsigned int seed);
The sequence of random numbers returned by rand() is initially controlled by a global
"seed" variable. srand() sets this seed which, by default, starts with the value 1. Pass
the expression time(NULL) (time.h) to set the seed to a value based on the current time to ensure that the random sequence is different from one run to the next.
void* malloc(size_t size);
Allocate a heap block of the given size in bytes. Returns a pointer to the block or
NULL on failure. A cast may be required to store the void* pointer into a regular
typed pointer. [ed: see the Heap Allocation section above for the longer discussion of
malloc(), free(), and realloc()]
void free(void* block);
Opposite of malloc(). Returns a previous malloc block to the system for reuse
void* realloc(void* block, size_t size);
Resize an existing heap block to the new size. Takes care of copying bytes from the
old block to the new. Returns the new base address of the heap block. It is a common
error to forget to catch the return value from realloc(). Returns NULL if the resize
operation was not possible.
void exit(int status);
Halt and exit the program and pass a condition int back to the operating sytem. Pass 0
to signal normal program termination, non-zero otherwise.
void* bsearch(const void* key, const void* base, size_t len, size_t elem_size, <compare_function>);
Do a binary search in an array of elements. The last argument is a function which takes pointers to the two elements to compare. Its prototype should be:
int compare(const void* a, const void* b);, and it should return 0, -1, or 1 as strcmp()
does. Returns a pointer to a found element, or NULL otherwise. Note that strcmp()
itself cannot be used directly as a compare function for bsearch() on an array of char*
strings because strcmp() takes char* arguments and bsearch() will need a comparator
that takes pointers to the array elements -- char**.
void qsort(void* base, size_t len, size_t elem_size,
Sort an array of elements. Takes a function pointer just like besearch().
Want To Know more with
Contact for more learning: webmaster@freehost7com