stdlib library
#include <stdlib.h>
Defined types and structures
- div_t - structure type that is the type of the value returned by
the div function
- ldiv_t - structure type that is the type of the value returned
by the ldiv function
- size_t - the unsigned integral type of the result of the
sizeof operator
- wchar_t - the integral type whose range of values can represent
distinct codes for all members of the largest
extended character set specified amount the supported
locales
Defined macros
- EXIT_FAILUREand EXIT_SUCCESS - may be used as arguments
to to exit() function.
- RAND_MAX - expands to an intgral constant expression whose
value is the maximum value returned by the rand
function
- MB_CUR_MAX - expands to a positive integer expression whose value
is the maiximum number of bytes in a multibyte
character for the extended character set
Functions
- double atof(const char *nptr);
converts the initial portion of a string pointed to by nptr to double
representation.
returns the converted value
equivalent to strtod(nptr, (char**)NULL)except for behavior on
an error
- int atoi(const char *nptr);
converts the initial portion of the string pointed to by nptr to an
integer representation.
returns the converted value
equivalent to (int)strtol(nptr, (char**)NULL, 10) except for
behavior on an error
- long int atol(const char *nptr);
converts the initial portion of the string pointed to by nptr to a
long integer representation.
returns the converted value
equivalent to (int)strtol(nptr, (char**)NULL, 10) except for
behavior on an error
- double strtod(const char *nptr, char **endptr);
converts the initial portion of a string pointed to by nptr to double
representation. It first divides the string into 3 parts, an initial
part consisting of 0 or more white space characters, a subject part
that resembles (i.e. is made of things allowed in) a floating point
value, and a final string of 1 or more unrecognizable characters
including the null terminator. It then attempts to convert the
subject portion to a floating point number. The "rest of the string"
is stored in the endprt so that the calling program has access to it.
If no conversion could take place, a 0 is returned. (This could be a
problem if the string to convert is 0. BRS)
- long int strtol(const char *nptr, char **endptr, int base)
Same as strtod() except returns a long int.
- unsigned long int strtoul(const char *nptr, char **endptr, int base);
Same as strtod() except returns an unsigned long int.
- int rand(void);
Returns an integer between 0 and RAND_MAX which is usually 1 less
then maximum size of an unsigned integer.
Should be used in conjunction with srand() for best results.
- void srand(unsigned int seed);
Returns nothing.
Uses the seed value to set up the random number generator. seed
should be a large prime for best results. You can use the value
returned from the time() function found in time.h to use the system
clock as a seed.
The srand() function should be used only once during any program
run. Reuse could cause the rand() function to return duplicate
numbers and/or numbers that are not very well randomized.
- void *malloc(size_t size);
- void *ralloc(void *ptr, size_t size);
- void abort(void)
- void *calloc(size_t nmemb, size_t size);
- void free(void *ptr);
- int atexit(void (*func)(void));
- void exit(int status);
- char *getenv(const char *name);
- int system(const char *string);
- void *bsearch(const void *key, const void *base, size_t nmemb,
size_t size, int (*compar)(const void *, const void *));
the int (*compar)(const void *, const void *); is a compare function
that has 2 void pointers as parameters.
- void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const
void *, const void *));
- int abs(int j);
- div_t div(int numer, int denom);
- long int labs(long int j);
- ldiv_t ldiv(long int numer, long int denom);
- int mblen(const char *s, size_t n);
- int mbtowc(wchar_t *pwc, const char *s, size_t n);
- int wctomb(char *s, wchar_t wchar);
- size_t mbstowcs(wchar_t *pwcs, const char *s, size_t n);
- size_t wcstombs(char *s, const wchar_t *pwcs, size_t n);
- This list of functions is complete. However, the descriptions are still
to come.