C Programming on the IBM PC (C Programmers Reference Guide Series)
|
|
Integer Format Conversion Functions
C99 adds a few specialized integer format conversion functions that allow you to convert to and from greatest-width integers. The header that supports these functions is <inttypes.h>, which includes <stdint.h>. The <inttypes.h> header defines one type: the structure imaxdiv_t, which holds the value returned by the imaxdiv( ) function. The integer conversion functions are shown here:
Function | Description |
---|---|
intmax_t imaxabs(intmax_t arg); | Returns the absolute value of arg. |
imaxdiv_t imaxdiv(intmax_t numerator, intmax_t denominator); | Returns an imaxdiv_t structure that contains the outcome of numerator/denominator. The quotient is the quot field and the remainder is in the rem field. Both quot and rem are of type intmax_t. |
intmax_t strtoimax(const char * restrict start, char ** restrict end, int base); | The greatest-width integer version of strtol( ). |
uintmax_t strtoumax(const char * restrict start, char ** restrict end, int base); | The greatest-width integer version of strtoul( ). |
intmax_t wcstoimax(const char * restrict start, char ** restrict end, int base); | The greatest-width integer version of wcstol( ). |
uintmax_t wcstoumax(const char * restrict start, char ** restrict end, int base); | The greatest-width integer version of wcstoul( ). |
<inttypes.h> also defines many macros that can be used in calls to the printf( ) and scanf( ) family of functions to specify various integer conversions. The printf( ) macros begin with PRI and the scanf( ) macros begin with SCN. These prefixes are then followed by a conversion specifier, such as d or u, and then a type name, such as N, MAX, PTR, FASTN, or LEASTN, where N specifies the number of bits. Consult your compiler's documentation for a precise list of conversion macros supported.
|
|