Appendix A

Commonly Used Utility Functions


Header Required: stdlib.h


EXIT_SUCCESS
EXIT_FAILURE
Constants defined which can be used when calling the exit function to return successful or unsuccessful termination of a program.

RAND_MAX
Constant value which represents the maximum value returned by the rand function.

double atof (const char source[]);
This function converts the string given into the equivalent value as a double precision value. If the string given cannot be represented as a double precision value then the function will return zero.

int atoi (const char source[]);
This function converts the string given into the equivalent value as an integer value. If the string given cannot be represented as an integer value then the function will return zero.

int rand (void);
This function will generate a pseudo-random number in the range of 0 to RAND_MAX. The value generated is returned from the function.

void srand (int seed);
This function will seed the number generator with a value to so that subsequent calls to rand will produce a series of psuedo-random numbers. If the same seed value is used eachtime a program is run then the rand function will produce the same sequence of pseudo-random numbers. Therefore each time a program is run a diiferent seed value should be used.

void exit (int status)
This function causes normal program termination to occur when called. The value given in status is the value returned back to the host environment. If the value is zero or EXIT_SUCCESS then the host environment will interpret that the program has completed successfully. If the value of status is EXIT_FAILURE then the host environment will interpret that the program has completed abnormally.

int abs (int n);
This function will return back the absolute value if n. If the result cannot be represented then the behaviour is undefined.


home