C Standard Library - <stdlib.h>


Introduction

stdlib .h The header file defines four variable types, some macros and various general utility functions.

Library variables

The following are the variable types defined in the header file stdlib.h:

Serial numberVariables & Description
1size_t
This is the unsigned integer type, which is the sizeof keyword result.
2wchar_t
This is a wide character constant-sized integer type.
3div_t
This is the structure returned by the div function.
4ldiv_t
This is the structure returned by the ldiv function.

Library macros

The following are the macros defined in the header file stdlib.h:

Serial numberMacro & Description
1NULL
This macro is the value of a null pointer constant.
2EXIT_FAILURE
This is the value to be returned when the exit function fails.
3EXIT_SUCCESS
This is the value to be returned when the exit function succeeds.
4RAND_MAX
This macro is the maximum value returned by the rand function.
5MB_CUR_MAX
This macro represents the maximum number of characters in the multi-byte character set, which cannot be greater than MB_LEN_MAX.

Library functions

The following are the functions defined in the header file stdlib.h:

Serial numberFunction & Description
1double atof(const char *str)
Convert the string pointed to by the parameter str into a floating point number (type double).
2int atoi(const char *str)
Convert the string pointed to by the parameter str to an integer (type is of type int).
3long int atol(const char *str)
Convert the string pointed to by the parameter str into a long integer (The type is long int).
4double strtod(const char *str, char **endptr)
Convert the string pointed to by the parameter str It is a floating point number (type double).
5long int strtol(const char *str, char **endptr, int base)
Parameter str points to The string is converted to a long integer (type long int).
6unsigned long int strtoul(const char *str, char **endptr, int base)
Put the parameters str The pointed-to string is converted to an unsigned long integer (type unsigned long int).
7void *calloc(size_t nitems, size_t size)
Allocate the required memory space and return a pointer to it.
8void free(void *ptr)
Calling calloc, malloc or realloc before releasing allocated memory space.
9void *malloc(size_t size)
Allocate the required memory space and return a pointer to it.
10void *realloc(void *ptr, size_t size)
Call malloc or calloc before trying to resize The size of the memory block pointed to by the allocated ptr.
11void abort(void)
Causes an abnormal program to terminate.
12int atexit(void (*func)(void))
When the program terminates normally, call the specified functionfunc.
13void exit(int status)
Cause the program to terminate normally.
14char *getenv(const char *name)
Search for the environment string pointed to by name and return the relevant value to the string.
15int system(const char *string)
The command specified by string is passed to the host environment to be executed by the command processor.
16void *bsearch(const void *key, const void *base, size_t nitems, size_t size, int (*compar)(const void *, const void *))
Perform binary search.
17void qsort(void *base, size_t nitems, size_t size, int (*compar)(const void *, const void*))
Array sorting.
18int abs(int x)
Returns the absolute value of x.
19div_t div(int numer, int denom)
Divide the numerator by the denominator.
20long int labs(long int x)
Returns the absolute value of x.
21ldiv_t ldiv(long int numer, long int denom)
Divide the numerator by the denominator.
22int rand(void)
Returns a pseudo-random number ranging from 0 to RAND_MAX.
23void srand(unsigned int seed)
This function seeds the random number generator used by function rand.
24int mblen(const char *str, size_t n)
Returns the multi-byte character pointed to by the parameter str length.
25size_t mbstowcs(schar_t *pwcs, const char *str, size_t n)
Change the number pointed to by the parameter str A string of byte characters is converted to the array pointed to by parameter pwcs.
26int mbtowc(whcar_t *pwc, const char *str, size_t n)
Check the parameter str points to Byte characters.
27size_t wcstombs(char *str, const wchar_t *pwcs, size_t n)
Put the encoding stored in the array pwcs Convert to multibyte characters and store them in the string str.
28int wctomb(char *str, wchar_t wchar)
Check the multibyte corresponding to the parameter wchar The encoding of the character.