The following functions, macros, and classes are provided in stdlib.h:
Name |
Description |
Header File stdlib.h Description Constants defining exit conditions for calls to the exit function. | |
Header File stdlib.h Syntax Description Maximum value returned by rand function. | |
Header File stdlib.h Syntax extern int _argc; Description _argc has the same value as argc (passed to main) when the program starts. This variable holds the number of arguments passed to the program. The value includes the name of the program itself, so _argc and argc are always at least 1. | |
Header File stdlib.h Syntax extern char **_argv; extern wchar_t ** _wargv Description _argv points to an array containing the original command-line arguments (the elements of argv[]) passed to main when the program starts. _wargv is the Unicode version of _argv. Portability | |
Header File stdlib.h Category Conversion Routines, Math Routines Prototype __int64 _atoi64(const char *s); __int64 _wtoi64(const wchar_t *s); Description Converts a string to an __int64. The syntax of the string must be: __int64 ::= [isspace]* [sign] digit [digit]* Only decimal integers are acceptable. _wtoi64 is the wide-character version. It converts a wide-character string to an __int64. In this function, the first unrecognized character ends the conversion. There are no provisions for overflow in atoi (results are undefined). There is no defined method to return an error indication to the caller. The result is undefined if the input string... more | |
Header File stdlib.h Category Math Routines Prototype unsigned char _crotl(unsigned char val, int count); unsigned char _crotr(unsigned char val, int count); Description Rotates an unsigned char left or right. _crotl rotates the given val to the left count bits. _crotr rotates the given val to the right count bits. The argument val is an unsigned char, or its equivalent in decimal or hexadecimal form. Return Value
| |
Header File stdlib.h Category Process Control Routines Prototype void _exit(int status); Description Terminates program. _exit terminates execution without closing any files, flushing any output, or calling any exit functions. The calling process uses status as the exit status of the process. Typically a value of 0 is used to indicate a normal exit, and a nonzero value indicates some error. Return Value None. Example | |
Header File stdlib.h Category Directory Control Routines Prototype char * _fullpath(char *buffer, const char *path, int buflen); wchar_t * _wfullpath(wchar_t *buffer, const wchar_t *path, int buflen); Description Converts a path name from relative to absolute. _fullpath converts the relative path name in path to an absolute path name that is stored in the array of characters pointed to by buffer. The maximum number of characters that can be stored at buffer is buflen. The function returns NULL if the buffer isn't big enough to store the absolute path name or if the path contains an invalid drive letter. If buffer... more | |
Header File stdlib.h Category Math Routines Prototype long _lrand(void); Description _lrand is the long random number generator function. _rand uses a multiplicative congruential random number generator with period 2^64 to return successive pseudo-random numbers in the range from 0 to 2^31 - 1. The generator is reinitialized by calling srand with an argument value of 1. It can be set to a new starting point by calling srand with a given seed number. | |
Header File stdlib.h Category Math Routines Prototype unsigned long _lrotl(unsigned long val, int count); unsigned long _lrotr(unsigned long val, int count); Description Rotates an unsigned long integer value to the left or right. _Irotlrotates the given val to the left count bits. _lrotr rotates the given val to the right count bits. Return Value The functions return the rotated integer:
| |
Header File stdlib.h Category Directory Control Routines Prototype void _makepath(char *path, const char *drive, const char *dir, const char *name, const char *ext); void _wmakepath(wchar_t *path, const wchar_t *drive, const wchar_t *dir, const wchar_t *name, const wchar_t *ext); Description Builds a path from component parts. _makepath makes a path name from its components. The new path name is X:\DIR\SUBDIR\NAME.EXT where | |
Header File stdlib.h Category Math Routines Prototype unsigned short _rotl(unsigned short value, int count); unsigned short _rotr(unsigned short value, int count); Description Bit-rotates an unsigned short integer value to the left or right. _rotl rotates the given value to the left count bits. _rotr rotates the given value to the right count bits. Return Value _rotl, and _rotr return the rotated integer:
| |
Header File stdlib.h Category Miscellaneous Routines Prototype char *_searchenv(const char *file, const char *varname, char *buf); char *_wsearchenv(const wchar_t *file, const wchar_t *varname, wchar_t *buf); Description Looks for a file, using an environment variable as the search path. _searchenv attempts to locate file, searching along the path specified by the operating system environment variable varname. Typical environment variables that contain paths are PATH, LIB, and INCLUDE. _searchenv searches for the file in the current directory of the current drive first. If the file is not found there, the environment variable varname is fetched, and each directory in the path it... more | |
Header File stdlib.h Category Miscellaneous Routines Prototype void _searchstr(const char *file, const char *ipath, char *buf); void _wsearchstr(const wchar_t *file, const wchar_t *ipath,wchar_t *pathname); Description Searches a list of directories for a file. _searchstr attempts to locate file, searching along the path specified by the string ipath. _searchstr searches for the file in the current directory of the current drive first. If the file is not found there, each directory in ipath is searched in turn until the file is found, or the path is exhausted. The directories in ipath must be separated by semicolons. When the file is located,... more | |
Header File stdlib.h Category Directory Control Routines Prototype void _splitpath(const char *path, char *drive, char *dir, char *name, char *ext); void _wsplitpath(const wchar_t *path, wchar_t *drive, wchar_t *dir, wchar_t *name, wchar_t *ext); Description Splits a full path name into its components. _splitpath takes a file's full path name (path) as a string in the form X:\DIR\SUBDIR\NAME.EXT and splits path into its four components. It then stores those components in the strings pointed to by drive, dir, name, and ext. (All five components must be passed, but any of them can be a null, which means the corresponding component will be... more | |
Header File stdlib.h Category Conversion Routines, Math Routines Prototype char *_ui64toa(unsigned __int64 value, char *string, int radix); wchar_t *_ui64tow(unsigned __int64 value, wchar_t *string, int radix); Description _ui64toa converts an unsigned __int64 to a string. _ui64tow is the unicode version. _ui64tow converts an unsigned __int64 to a wide-character string. These functions convert value to a null-terminated string and store the result in string. value is an __int64. radix specifies the base to be used in converting value; it must be between 2 and 36, inclusive. If value is negative and radix is 10, the first character of string is... more | |
Header File stdlib.h Category Process Control Routines Prototype void abort(void); Description Abnormally terminates a program. abort causes an abnormal program termination by calling raise(SIGABRT). If there is no signal handler for SIGABRT, then abort writes a termination message (Abnormal program termination) on stderr, then aborts the program by a call to _exit with exit code 3. Return Value abort returns the exit code 3 to the parent process or to the operating system command processor. Example | |
Header File stdlib.h Category Process Control Routines Prototype int atexit(void (_USERENTRY * func)(void)); Description Registers termination function. atexit registers the function pointed to by func as an exit function. Upon normal termination of the program, exit calls func just before returning to the operating system. fcmp must be used with the _USERENTRY calling convention. Each call to atexit registers another exit function. Up to 32 functions can be registered. They are executed on a last-in, first-out basis (that is, the last function registered is the first to be executed). Return Value atexit returns 0 on success and nonzero on failure... more | |
Header File stdlib.h Category Conversion Routines, Math Routines Prototype int atoi(const char *s); int _wtoi(const wchar_t *s); Description Converts a string to an integer.
[ws] [sn] [ddd] In this function, the first unrecognized character ends the conversion. There are no provisions for overflow in atoi (results are undefined). Return Value atoi returns the converted value of the input string. If the... more | |
Header File stdlib.h Category Conversion Routines, Math Routines Prototype long atol(const char *s); long _wtol(const wchar_t *s); Description Converts a string to a long.
[ws] [sn] [ddd] In this function, the first unrecognized character ends the conversion. There are no provisions for overflow in atol (results are undefined). Return Value atol returns the converted value of the input string. If the... more | |
Header File stdlib.h Category Memory and String Manipulation Routines Prototype void *bsearch(const void *key, const void *base, size_t nelem, size_t width, int (_USERENTRY *fcmp)(const void *, const void *)); Description Binary search of an array. bsearch searches a table (array) of nelem elements in memory, and returns the address of the first entry in the table that matches the search key. The array must be in order. If no match is found, bsearch returns 0. Note: Because this is a binary search, the first matching entry is not necessarily the first entry in the table. The type size_t is defined... more | |
Header File stdlib.h Category Math Routines Prototype div_t div(int numer, int denom); Description Divides two integers, returning quotient and remainder. div divides two integers and returns both the quotient and the remainder as a div_t type. numer and denom are the numerator and denominator, respectively. The div_t type is a structure of integers defined (with typedef) in stdlib.h as follows: typedef struct { int quot; /* quotient */ int rem; /* remainder */ } div_t; Return Value div returns a structure whose elements are quot (the quotient) and rem (the remainder). Example | |
Header File stdlib.h Category Conversion Routines, Math Routines Prototype char *ecvt(double value, int ndig, int *dec, int *sign); Description Converts a floating-point number to a string. ecvt converts value to a null-terminated string of ndig digits, starting with the leftmost significant digit, and returns a pointer to the string. The position of the decimal point relative to the beginning of the string is stored indirectly through dec (a negative value for dec means that the decimal lies to the left of the returned digits). There is no decimal point in the string itself. If the sign of value is... more | |
Header File stdlib.h Syntax extern char ** _environ; extern wchar_t ** _wenviron Description _environ is an array of pointers to strings; it is used to access and alter the operating system environment variables. Each string is of the form: envvar = varvalue where envvar is the name of an environment variable (such as PATH), and varvalue is the string value to which envvar is set (such as C:\Utils;C:\MyPrograms). The string varvalue can be empty. When a program begins execution, the operating system environment settings are passed directly to the program. Note that env, the third argument to main, is equal... more | |
Header File stdlib.h Category Process Control Routines Prototype void exit(int status); Description Terminates program. exit terminates the calling process. Before termination, all files are closed, buffered output (waiting to be output) is written, and any registered "exit functions" (posted with atexit) are called. status is provided for the calling process as the exit status of the process. Typically a value of 0 is used to indicate a normal exit, and a nonzero value indicates some error. It can be, but is not required, to be set with one of the following: | |
Header File stdlib.h Category Conversion Routines, Math Routines Prototype char *fcvt(double value, int ndig, int *dec, int *sign); Description Converts a floating-point number to a string. fcvt converts value to a null-terminated string digit starting with the leftmost significant digit with ndig digits to the right of the decimal point. fcvt then returns a pointer to the string. The position of the decimal point relative to the beginning of the string is stored indirectly through dec (a negative value for dec means to the left of the returned digits). There is no decimal point in the string itself. If... more | |
Header File stdlib.h Category Conversion Routines, Math Routines Prototype char *gcvt(double value, int ndec, char *buf); Description Converts floating-point number to a string. gcvt converts value to a null-terminated ASCII string and stores the string in buf. It produces ndec significant digits in FORTRAN F format, if possible; otherwise, it returns the value in the printf E format (ready for printing). It might suppress trailing zeros. Return Value gcvt returns the address of the string pointed to by buf. Example | |
Header File stdlib.h Category Process Control Routines Prototype char *getenv(const char *name); wchar_t *_wgetenv(const wchar_t *name); Description Find or delete an environment variable from the system environment. The environment consists of a series of entries that are of the form name=string\0. getenv returns the value of a specified variable. name can be either uppercase or lowercase. name must not include the equal sign (=). If the specified environment variable does not exist, getenv returns a NULL pointer. To delete the variable from the environment, use getenv("name="). Note: Environment entries must not be changed directly. If you want to... more | |
Header File stdlib.h Category Conversion Routines, Math Routines Prototype char *itoa(int value, char *string, int radix); wchar_t *_itow(int value, wchar_t *string, int radix); Description Converts an integer to a string. itoa converts value to a null-terminated string and stores the result in string. With itoa, value is an integer. _itow is the unicode version of the function. It converts an integer to a wide-character string. radix specifies the base to be used in converting value; it must be between 2 and 36, inclusive. If value is negative and radix is 10, the first character of string is the minus... more | |
Header File stdlib.h Category Math Routines Prototype long labs(long int x); Description Gives long absolute value. labs computes the absolute value of the parameter x. Return Value labs returns the absolute value of x. Example | |
Header File stdlib.h Category Memory and String Manipulation Routines Prototype void *lfind(const void *key, const void *base, size_t *num, size_t width, int (_USERENTRY *fcmp)(const void *, const void *)); Description Performs a linear search. lfind makes a linear search for the value of key in an array of sequential records. It uses a user-defined comparison routine fcmp. The fcmp function must be used with the _USERENTRY calling convention. The array is described as having *num records that are width bytes wide, and begins at the memory location pointed to by base. Return Value lfind returns the address of the first... more | |
Header File stdlib.h Category Memory and String Manipulation Routines Prototype void *lsearch(const void *key, void *base, size_t *num, size_t width, int (_USERENTRY *fcmp)(const void *, const void *)); Description Performs a linear search. lsearch searches a table for information. Because this is a linear search, the table entries do not need to be sorted before a call to lsearch. If the item that key points to is not in the table, lsearch appends that item to the table.
| |
Header File stdlib.h Category Conversion Routines, Math Routines Prototype char * ltoa(long value, char * string, int radix); char *_ltoa(long value, char *string, int radix); wchar_t *_ltow(long value, wchar_t *string, int radix); Description Converts a long to a string. _ltow is the unicode version. It converts a long to a wide-charater string. Converts value to a null-terminated string and stores the result in string. value is a long. radix specifies the base to be used in converting value; it must be between 2 and 36, inclusive. If value is negative and radix is 10, the first character of... more | |
Header File stdlib.h Category C++ Prototyped Routines Prototype (type) max(a, b); template <class T> T max( T t1, T t2 ); // C++ only Description Returns the larger of two values. The C macro and the C++ template function compare two values and return the larger of the two. Both arguments and the routine declaration must be of the same type. Return Value max returns the larger of two values. Portability | |
Header File stdlib.h Category Memory and String Manipulation Routines Prototype int mblen(const char *s, size_t n); Description Determines the length of a multibyte character. If s is not null, mblen determines the number of bytes in the multibyte character pointed to by s. The maximum number of bytes examined is specified by n. The behavior of mblen is affected by the setting of LC_CTYPE category of the current locale. Return Value If s is null, mblen returns a nonzero value if multibyte characters have state-dependent encodings. Otherwise, mblen returns 0. If s is not null, mblen returns 0 if s... more | |
Header File stdlib.h Category Conversion Routines, Memory and String Manipulation Routines Prototype size_t mbstowcs(wchar_t *pwcs, const char *s, size_t n); Description Converts a multibyte string to a wchar_t array. The function converts the multibyte string s into the array pointed to by pwcs. No more than n values are stored in the array. If an invalid multibyte sequence is encountered, mbstowcs returns (size_t) -1. The pwcs array will not be terminated with a zero value if mbstowcs returns n. Return Value If an invalid multibyte sequence is encountered, mbstowcs returns (size_t) -1. Otherwise, the function returns the number of array... more | |
Header File stdlib.h Category Conversion Routines, Memory and String Manipulation Routines Prototype int mbtowc(wchar_t *pwc, const char *s, size_t n); Description Converts a multibyte character to wchar_t code. If s is not null, mbtowc determines the number of bytes that comprise the multibyte character pointed to by s. Next, mbtowc determines the value of the type wchar_t that corresponds to that multibyte character. If there is a successful match between wchar_t and the multibyte character, and pwc is not null, the wchar_t value is stored in the array pointed to by pwc. At most n characters are examined. Return Value... more | |
Header File stdlib.h Category C++ Prototyped Routines Prototype (type) min(a, b); /* macro version */ template <class T> T min( T t1, T t2 );// C++ only Description Returns the smaller of two values. The C macro and the C++ template function compare two values and return the smaller of the two. Both arguments and the routine declaration must be of the same type. Return Value min returns the smaller of two values. | |
Header File stdlib.h Category Process Control Routines Prototype int putenv(const char *name); int _wputenv(const wchar_t *name); Description Adds string to current environment. putenv accepts the string name and adds it to the environment of the current process. For example, putenv(“PATH=C:\\BC”); putenv can also be used to modify an existing name. name can be either uppercase or lowercase. name must not include the equal sign (=). You can set a variable to an empty value by specifying an empty string on the right side of the ‘=’ sign. putenv can be used only to modify the current program’s _environment.... more | |
Header File stdlib.h Category Memory and String Manipulation Routines Prototype void qsort(void *base, size_t nelem, size_t width, int (_USERENTRY *fcmp)(const void *, const void *)); Description Sorts using the quicksort algorithm. qsort is an implementation of the “median of three” variant of the quicksort algorithm. qsort sorts the entries in a table by repeatedly calling the user-defined comparison function pointed to by fcmp.
| |
Header File stdlib.h Category Math Routines Prototype int rand(void); Description Random number generator. rand uses a multiplicative congruential random number generator with period 2 to the 32nd power to return successive pseudo-random numbers in the range from 0 to RAND_MAX. The symbolic constant RAND_MAX is defined in stdlib.h. Return Value rand returns the generated pseudo-random number. Example | |
Header File stdlib.h Category Math Routines Prototype int random(int num); Description Random number generator. random returns a random number between 0 and (num-1). random(num) is a macro defined in stdlib.h. Both num and the random number returned are integers. Return Value random returns a number between 0 and (num-1). Example | |
Header File stdlib.h, time.h Category Math Routines Prototype void randomize(void); Description Initializes random number generator. randomize initializes the random number generator with a random value. Return Value None. Example | |
Header File stdlib.h Category Math Routines Prototype void srand(unsigned seed); Description Initializes random number generator. The random number generator is reinitialized by calling srand with an argument value of 1. It can be set to a new starting point by calling srand with a given seed number. Return Value None. Example | |
Header File string.h, mbstring.h, stdlib.h Category Memory and String Manipulation Routines, Inline Routines Prototype size_t strlen(const char *s); size_t wcslen(const wchar_t *s); size_t _mbslen(const unsigned char *s); size_t _mbstrlen(const char *s) Description Calculates the length of a string. strlen calculates the length of s. _mbslen and _mbstrlen test the string argument to determine the number of multibyte characters they contain. _mbstrlen is affected by the LC_CTYPE category setting as determined by the setlocale function. The function tests to determine whether the string argument is a valid multibyte string. _mbslen is affected by the code page that is in use. This... more | |
Header File stdlib.h Category Conversion Routines, Math Routines Prototype double strtod(const char *s, char **endptr); double wcstod(const wchar_t *s, wchar_t **endptr); long double _strtold(const char *s, char **endptr); long double _wcstold(const wchar_t *s, wchar_t **endptr); Description Convert a string to a double or long double value. strtod converts a character string, s, to a double value. s is a sequence of characters that can be interpreted as a double value; the characters must match this generic format: [ws] [sn] [ddd] [.] [ddd] [fmt[sn]ddd] where: | |
Header File stdlib.h Category Conversion Routines, Math Routines Prototype long strtol(const char *s, char **endptr, int radix); long wcstol(const wchar_t *s, wchar_t **endptr, int radix); Description Converts a string to a long value. strtol converts a character string, s, to a long integer value. s is a sequence of characters that can be interpreted as a long value; the characters must match this generic format: [ws] [sn] [0] [x] [ddd] where: | |
Header File stdlib.h Category Conversion Routines, Math Routines Prototype unsigned long strtoul(const char *s, char **endptr, int radix); unsigned long wcstoul(const wchar_t *s, wchar_t **endptr, int radix); Description Converts a string to an unsigned long in the given radix. strtoul operates the same as strtol, except that it converts a string str to an unsigned long value (where strtol converts to a long). Refer to the entry for strtol for more information. Return Value strtoul returns the converted value, an unsigned long, or 0 on error. Example | |
Header File stdlib.h Category Memory and String Manipulation Routines Prototype void swab(char *from, char *to, int nbytes); Description Swaps bytes. swab copies nbytes bytes from the from string to the to string. Adjacent even- and odd-byte positions are swapped. This is useful for moving data from one machine to another machine with a different byte order. nbytes should be even. Return Value None. Example | |
Header File stdlib.h Category Process Control Routines Prototype int system(const char *command); int _wsystem(const wchar_t *command); Description Issues an operating system command. system invokes the operating system command processor to execute an operating system command, batch file, or other program named by the string command, from inside an executing C program. To be located and executed, the program must be in the current directory or in one of the directories listed in the PATH string in the environment. The COMSPEC environment variable is used to find the command processor program, so it need not be in the current directory. Return... more | |
Header File stdlib.h Category Conversion Routines, Math Routines Prototype char *ultoa(unsigned long value, char *string, int radix); wchar_t *_ultow(unsigned long value, wchar_t *string, int radix); Description Converts an unsigned long to a string. ultoa converts value to a null-terminated string and stores the result in string. value is an unsigned long. radix specifies the base to be used in converting value; it must be between 2 and 36, inclusive. ultoa performs no overflow checking, and if value is negative and radix equals 10, it does not set the minus sign. Note: The space allocated for string must be... more | |
Header File stdlib.h Category Conversion Routines, Memory and String Manipulation Routines Prototype size_t wcstombs(char *s, const wchar_t *pwcs, size_t n); Description Converts a wchar_t array into a multibyte string. wcstombs converts the type wchar_t elements contained in pwcs into a multibyte character string s. The process terminates if either a null character or an invalid multibyte character is encountered. No more than n bytes are modified. If n number of bytes are processed before a null character is reached, the array s is not null terminated. The behavior of wcstombs is affected by the setting of LC_CTYPE category of the... more | |
Header File stdlib.h Category Conversion Routines, Memory and String Manipulation Routines Prototype int wctomb(char *s, wchar_t wc); Description Converts wchar_t code to a multibyte character. If s is not null, wctomb determines the number of bytes needed to represent the multibyte character corresponding to wc (including any change in shift state). The multibyte character is stored in s. At most MB_CUR_MAX characters are stored. If the value of wc is zero, wctomb is left in the initial state. The behavior of wctomb is affected by the setting of LC_CTYPE category of the current locale. Return Value If s is a... more |
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|