![]() |
C - Entwicklung Thema: Conversion, Cast, Umwandlung von Daten und Typen Homepage von PS-Trainer - C-Entwicklung - Bibliotheken - an PS-Trainer |
|
| Fundamental Types | Fundamental Types in C++ |
| Type Cast | A type cast provides a method for explicit conversion of
the type of an object in a specific situation. Type Cast Operator, Type-Cast Conversions, Cast Operators, Demotion of Integers, Casting Integers to Floating-Point Values, Conversions from Unsigned Integral Types, Explicit Type Conversion Operator, Ambiguity Resolution, Casting and Class Hierarchy, reinterpret_cast Operator, static_cast Operator, dynamic_cast Operator, Conversion Functions, |
| Data Conversion Routines | These routines convert data from one form to another |
| STRICT type checking | Defining the STRICT symbol enables features that enable you to write more portable code. |
| Functions That Require Casts | Some functions have generic return types or parameters (any number of types, depending on the context). |
| sizeof
Operator |
The sizeof keyword gives the amount of storage, in bytes, associated with a variable or a type (including aggregate types). |
| _ltoa, _ltow | Convert a long integer to a string. |
| _itoa, _i64toa, _ui64toa, _itow, _i64tow, _ui64tow | Convert an integer to a string. |
| _ultoa,
_ultow |
Convert an unsigned long integer to a string. |
| _fcvt
|
Converts a floating-point number to a string. |
| _gcvt | Converts a floating-point value to a string, which it stores in a buffer. |
| _ecvt | Converts a double number to a string. |
| atof,
atoi, _atoi64, atol |
Convert strings to double (atof), integer (atoi, _atoi64), or long (atol). |
| strtod,
wcstod strtol, wcstol strtoul, wcstoul |
Convert input string nptr to a double-precision value, a long-integer value, or an unsigned long-integer value, respectively. |
| strtol,
wcstol |
Convert strings to a long-integer value. |
| strtoul,
wcstoul |
Convert strings to an unsigned long-integer value. |
| strtod,
wcstod |
Convert strings to a double-precision value. |
| to
Functions |
Each of the to functions and its associated macro, if any, converts
a single character to another character. __toascii, toupper, _toupper, towupper tolower, _tolower, towlower |
| Fundamental Types Fundamental types in C++ are divided into three categories: "integral," "floating," and "void." No variable of type void can be specified it is used primarily to declare functions that return no values or to declare "generic" pointers to untyped or arbitrarily typed data. Any expression can be explicitly converted or cast to type void. However, such expressions are restricted to the following uses: The following table explains the restrictions on type sizes. These restrictions are independent of the Microsoft implementation. Fundamental Types of the C++ Language
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| Data Conversion These routines convert data from one form to another. Generally these routines execute faster than conversions you might write. Each routine that begins with a to prefix is implemented as a function and as a macro. See Choosing Between Functions and Macros for information about choosing an implementation. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| Using STRICT to Improve Type Checking Defining the STRICT symbol enables features that require you to be more careful in declaring and using types. This may sound like a burden, but it is actually an aid to writing more portable code. This extra care will also reduce the time you spend debugging. Enabling STRICT redefines certain data types so that the compiler wont permit assignment from one type to another without an explicit cast. This is especially helpful with Windows code. Errors in passing data types are reported at compile time instead of causing fatal errors at run time. When STRICT is defined, WINDOWS.H type definitions change as follows: |
||||||||||
| Making Your Application STRICT Compliant Some source code that in the past compiled successfully might produce error messages when you enable STRICT type checking. The following sections describe the minimal requirements you need to follow, where applicable, to make sure your code compiles when STRICT is enabled. There are other steps not strictly required but recommended, especially if you want to produce portable code. These are covered in General Requirements The principal requirement is that you must declare correct handle types and function pointers instead of relying on more general types such as unsigned int and FARPROC. You cannot use one handle type where another is expected. This requirement also means that you may have to change function declarations and use more type casts. For best results, the generic HANDLE type should not be used except where necessary. Consult Using Function Pointers Always declare function pointers with the proper function type (such as DLGPROC or WNDPROC) rather than FARPROC. Youll need to cast function pointers to and from the proper function type when using MakeProcInstance, FreeProcInstance, and other functions that take or return a FARPROC, as shown in the following code: BOOL CALLBACK DlgProc(HWND
hwnd, UINT msg, WPARAM wParam, | ||||||||||
| Making Best Use of STRICT Type Checking To get the most benefit from STRICT type checking, there are other guidelines you should follow in addition to those in Making Your Application STRICT Compliant. Your code will be more portable in future versions of Windows if you make the following changes:
Any time you need an integer data type, you should declare it as UINT except where a 16-bit value is specifically required (as in a structure or parameter). For even if a variable never exceeds the range of a 16-bit integer, it can be more efficiently handled by the processor if it is 32 bits. The types WPARAM, LPARAM, LRESULT, and void * are polymorphic data types: they hold different kinds of data at different times, even when STRICT type checking is enabled. To get the benefit of type checking, you should cast values of these types as soon as possible. Note that message crackers (as well as the Microsoft Foundation Classes) automatically recast wParam and lParam for you in a portable way. Take special care to distinguish HMODULE and HINSTANCE types. Even with STRICT enabled, they are defined as the same base type. Most kernel module management functions use HINSTANCE types, but there are a few functions that return or accept only HMODULE types. | ||||||||||
| Replace the WORD cast by HWND cast Source code written for 16-bit Windows often uses the type WORD interchangeably with types such as HWND and HANDLE. For example, the typecast (WORD) might be used to cast a data type to a handle: hWnd = (WORD) SendMessage( hWnd, WM_GETMDIACTIVATE, 0, 0 ); This code compiles correctly with a 16-bit compiler, because both the WORD type and handles are 16 bits. However, the code does not compile correctly with a 32-bit compiler, because handles are 32 bits while the WORD type is still 16 bits. To make this example portable, replace the WORD cast by HWND cast, as shown: hWnd = (HWND) SendMessage( hWnd, WM_GETMDIACTIVATE, 0, 0 ); To write portable code, examine each WORD cast and WORD definition
in your code, and revise as follows: |
| Functions That Require Casts Some functions have generic return types or parameters. For example, a function like SendMessage returns data that may be any number of types, depending on the context. When you see any of these functions in your source code, make sure that you use the correct type cast and that it is as specific as possible. The following table summarizes these functions:
When you call SendMessage, DefWindowProc, or SendDlgItemMessage, you should first cast the result to type UINT. You need to take similar steps for any function that returns LRESULT or LONG, where the result contains a handle. This is necessary for writing portable code because the size of a handle is either 16 bits or 32 bits depending on the version of Windows. The (UINT) cast ensures proper conversion. The following code shows an example in which SendMessage returns a handle to a brush: HBRUSH hbr;hbr = (HBRUSH)(UINT)SendMessage(hwnd, WM_CTLCOLOR, ..., ...); |
| _fcvt Converts a floating-point number to a string. char *_fcvt( double value, int count, int *dec, int *sign );
Remarks The _fcvt function converts a floating-point number to a null-terminated character string. The value parameter is the floating-point number to be converted. _fcvt stores the digits of value as a string and appends a null character ('\0'). The count parameter specifies the number of digits to be stored after the decimal point. Excess digits are rounded off to count places. If there are fewer than count digits of precision, the string is padded with zeros. Only digits are stored in the string. The position of the decimal point and the sign of value can be obtained from dec and sign after the call. The dec parameter points to an integer value; this integer value gives the position of the decimal point with respect to the beginning of the string. A zero or negative integer value indicates that the decimal point lies to the left of the first digit. The parameter sign points to an integer indicating the sign of value. The integer is set to 0 if value is positive and is set to a nonzero number if value is negative. _ecvt and _fcvt use a single statically allocated buffer for the conversion. Each call to one of these routines destroys the results of the previous call. Subject: Data Conversion Routines | Floating-Point Support Routines Keywords: See also atof, _ecvt, _gcvt |
||||||||
| Return Value _fcvt returns a pointer to the string of digits. There is no error return. Parameters
|
||||||||
|
Example #include <stdlib.h> void main( void ) buffer = _fcvt( source, 7,
&decimal, &sign ); |
|
_ltoa, _ltow
Remarks The _ltoa function converts the digits of value to a null-terminated character string and stores the result (up to 33 bytes) in string. The radix argument specifies the base of value, which must be in the range 2 36. If radix equals 10 and value is negative, the first character of the stored string is the minus sign (). _ltow is a wide-character version of _ltoa; the second argument and return value of _ltow are wide-character strings. Each of these functions is Microsoft-specific. Generic-Text Routine Mappings
Subject: Data Conversion Routines Keywords: See also _itoa, _ultoa |
|||||||||||||||||||||
| Return Value Each of these functions returns a pointer to string. There is no error return. Parameters
|
|||||||||||||||||||||
|
Example #include <stdlib.h> void main( void ) _itoa( i, buffer, 10 ); _ltoa( l, buffer, 16 ); _ultoa( ul, buffer, 16 ); |
| _itoa, _i64toa,
_ui64toa, _itow, _i64tow, _ui64tow Convert an integer to a string. char *_itoa( int value, char *string, int radix ); char *_i64toa( __int64 value, char *string, int radix ); char * _ui64toa( unsigned _int64 value, char *string, int radix ); wchar_t * _itow( int value, wchar_t *string, int radix ); wchar_t * _i64tow( __int64 value, wchar_t *string, int radix ); wchar_t * _ui64tow( unsigned __int64 value, wchar_t *string, int radix );
Remarks The _itoa, _i64toa, and _ui64toa function convert the digits of the given value argument to a null-terminated character string and stores the result (up to 17 bytes) in string. If radix equals 10 and value is negative, the first character of the stored string is the minus sign ( ). _itow, _i64tow, and _ui64tow are wide-character versions of _itoa, _i64toa, and _ui64toa respectively. Generic-Text Routine Mappings
Subject: Data Conversion Routines Keywords: See also _ltoa, _ultoa |
|||||||||||||||||||||||||||||||||
| Return Value Each of these functions returns a pointer to string. There is no error return. Parameters
|
|||||||||||||||||||||||||||||||||
|
Example #include <stdlib.h> void main( void ) _itoa( i, buffer, 10 ); _ltoa( l, buffer, 16 ); _ultoa( ul, buffer, 16 ); |
|
atof, atoi, _atoi64, atol
Remarks These functions convert a character string to a double-precision floating-point value (atof), an integer value (atoi and _atoi64), or a long integer value (atol). The input string is a sequence of characters that can be interpreted as a numerical value of the specified type. The output value is affected by the setting of the LC_NUMERIC category in the current locale. For more information on the LC_NUMERIC category, see setlocale. The longest string size that atof can handle is 100 characters. The function stops reading the input string at the first character that it cannot recognize as part of a number. This character may be the null character ('\0') terminating the string. The string argument to atof has the following form: [whitespace] [sign] [digits] [.digits] [ {d | D | e | E }[sign]digits] A whitespace consists of space and/or tab characters, which are ignored; sign is either plus (+) or minus ( ); and digits are one or more decimal digits. If no digits appear before the decimal point, at least one must appear after the decimal point. The decimal digits may be followed by an exponent, which consists of an introductory letter ( d, D, e, or E) and an optionally signed decimal integer. atoi, _atoi64, and atol do not recognize decimal points or exponents. The string argument for these functions has the form: [whitespace] [sign]digits where whitespace, sign, and digits are exactly as described above for atof. Generic-Text Routine Mappings
Subject: Data Conversion Routines | Floating-Point Support Routines | Locale Routines Keywords: See Also _ecvt, _fcvt, _gcvt, setlocale, strtod, wcstol, strtoul |
|||||||||||||||||||||||||||||||
| Return Value Each function returns the double, int, __int64 or long value produced by interpreting the input characters as a number. The return value is 0 (for atoi and _atoi64), 0L (for atol), or 0.0 (for atof) if the input cannot be converted to a value of that type. The return value is undefined in case of overflow. Parameter
|
|||||||||||||||||||||||||||||||
|
Example #include <stdlib.h> void main( void ) s = " -2309.12E-15";
/* Test of atof */ s = "7.8912654773d210";
/* Test of atof */ s = " -9885 pigs";
/* Test of atoi */ s = "98854 dollars";
/* Test of atol */ |
|
strtoul, wcstoul
Remarks Each of these functions converts the input string nptr to an unsigned long. strtoul stops reading the string nptr at the first character it cannot recognize as part of a number. This may be the terminating null character, or it may be the first numeric character greater than or equal to base. The LC_NUMERIC category setting of the current locale determines recognition of the radix character in nptr; for more information, see setlocale. If endptr is not NULL, a pointer to the character that stopped the scan is stored at the location pointed to by endptr. If no conversion can be performed (no valid digits were found or an invalid base was specified), the value of nptr is stored at the location pointed to by endptr. wcstoul is a wide-character version of strtoul; its nptr argument is a wide-character string. Otherwise these functions behave identically. Generic-Text Routine Mappings
strtoul expects nptr to point to a string of the following form: [whitespace] [{+ | }] [0 [{ x | X }]] [digits] A whitespace may consist of space and tab characters, which are ignored; digits are one or more decimal digits. The first character that does not fit this form stops the scan. If base is between 2 and 36, then it is used as the base of the number. If base is 0, the initial characters of the string pointed to by nptr are used to determine the base. If the first character is 0 and the second character is not 'x' or 'X', the string is interpreted as an octal integer; otherwise, it is interpreted as a decimal number. If the first character is '0' and the second character is 'x' or 'X', the string is interpreted as a hexadecimal integer. If the first character is '1' through '9', the string is interpreted as a decimal integer. The letters 'a' through 'z' (or 'A' through 'Z') are assigned the values 10 through 35; only letters whose assigned values are less than base are permitted. strtoul allows a plus (+) or minus () sign prefix; a leading minus sign indicates that the return value is negated. Subject: Data Conversion Routines, Locale Routines | strtod Functions Overview Keywords: See Also strtod, strtol, atof, localeconv, setlocale |
|||||||||||||||||||||
| Return Value strtoul returns the converted value, if any, or ULONG_MAX on overflow. strtoul returns 0 if no conversion can be performed. wcstoul returns values analogously to strtoul. For both functions, errno is set to ERANGE if overflow or underflow occurs. Parameters
|
|||||||||||||||||||||
|
Example #include <stdlib.h> void main( void ) string = -10110134932This
stopped it strtol = -2147483647 Stopped scan at: This stopped itstring
= 10110134932 |
|
_ecvt
Remarks The _ecvt function converts a floating-point number to a character string. The value parameter is the floating-point number to be converted. This function stores up to count digits of value as a string and appends a null character ('\0'). If the number of digits in value exceeds count, the low-order digit is rounded. If there are fewer than count digits, the string is padded with zeros. Only digits are stored in the string. The position of the decimal point and the sign of value can be obtained from dec and sign after the call. The dec parameter points to an integer value giving the position of the decimal point with respect to the beginning of the string. A 0 or negative integer value indicates that the decimal point lies to the left of the first digit. The sign parameter points to an integer that indicates the sign of the converted number. If the integer value is 0, the number is positive. Otherwise, the number is negative. _ecvt and _fcvt use a single statically allocated buffer for the conversion. Each call to one of these routines destroys the result of the previous call. Subject: Data Conversion Routines | Floating-Point Support Routines Keywords: See Also atof, _fcvt, _gcvt |
||||||||
| Return Value _ecvt returns a pointer to the string of digits. There is no error return. Parameters
|
||||||||
|
Example #include <stdlib.h> void main( void ) buffer = _ecvt( source, precision,
&decimal, &sign ); |
| to Functions Each of the to functions and its associated macro, if any, converts a single character to another character. __toascii toupper, _toupper, towupper tolower, _tolower, towlower
To use the function versions of the to routines that are also defined as macros, either remove the macro definitions with #undef directives or do not include CTYPE.H. If you use the /Za compiler option, the compiler uses the function version of toupper or tolower. Declarations of the toupper and tolower functions are in STDLIB.H. The __toascii routine sets all but the low-order 7 bits of c to 0, so that the converted value represents a character in the ASCII character set. If c already represents an ASCII character, c is unchanged. The tolower and
toupper routines: Subject: Data Conversion Routines | Locale Routines |
||||||||||||||||||||||||
|
Example #include <conio.h> char msg[] = "Some of
THESE letters are Capitals\r\n"; void main( void ) /* Reverse case of message.
*/ Output |
|
__toascii Converts characters. int __toascii( int c );
Remarks The __toascii routine converts the given character to an ASCII character. Subject: Data Conversion Routines Keywords: to Functions. |
||||||
| Return Value __toascii converts a copy of c if possible, and returns the result. There is no return value reserved to indicate an error. Parameter
|
||||||
|
Example #include <conio.h> char msg[] = "Some of
THESE letters are Capitals\r\n"; void main( void ) /* Reverse case of message.
*/ Output |
| strtod, strtol, strtoul Functions strtod, wcstod strtol, wcstol strtoul, wcstoul Remarks The strtod, strtol, and strtoul functions convert nptr to a double-precision value, a long-integer value, or an unsigned long-integer value, respectively. The input string nptr is a sequence of characters that can be interpreted as a numerical value of the specified type. Each function stops reading the string nptr at the first character it cannot recognize as part of a number. This may be the terminating null character. For strtol or strtoul, this terminating character can also be the first numeric character greater than or equal to base. For all six functions in the strtod group, the current locale's LC_NUMERIC category setting determines recognition of the radix character in nptr; for more information, see setlocale. If endptr is not NULL, a pointer to the character that stopped the scan is stored at the location pointed to by endptr. If no conversion can be performed (no valid digits were found or an invalid base was specified), the value of nptr is stored at the location pointed to by endptr. strtod expects nptr to point to a string of the following form: [whitespace] [sign] [digits] [.digits] [ {d | D | e | E}[sign]digits] A whitespace may consist of space or tab characters, which are ignored; sign is either plus (+) or minus (); and digits are one or more decimal digits. If no digits appear before the radix character, at least one must appear after the radix character. The decimal digits can be followed by an exponent, which consists of an introductory letter (d, D, e, or E) and an optionally signed integer. If neither an exponent part nor a radix character appears, a radix character is assumed to follow the last digit in the string. The first character that does not fit this form stops the scan. The strtol and strtoul functions expect nptr to point to a string of the following form: [whitespace] [{+ | }] [0 [{ x | X }]] [digits] If base is between 2 and 36, then it is used as the base of the number. If base is 0, the initial characters of the string pointed to by nptr are used to determine the base. If the first character is 0 and the second character is not 'x' or 'X', the string is interpreted as an octal integer; otherwise, it is interpreted as a decimal number. If the first character is '0' and the second character is 'x' or 'X', the string is interpreted as a hexadecimal integer. If the first character is '1' through '9', the string is interpreted as a decimal integer. The letters 'a' through 'z' (or 'A' through 'Z') are assigned the values 10 through 35; only letters whose assigned values are less than base are permitted. strtoul allows a plus (+) or minus () sign prefix; a leading minus sign indicates that the return value is negated. wcstod, wcstol, and wcstoul are wide-character versions of strtod, strtol, and strtoul, respectively; the nptr argument to each of these wide-character functions is a wide-character string. Otherwise, each of these wide-character functions behaves identically to its single-bytecharacter counterpart. Subject: Data Conversion Routines | Floating-Point Support Routines | Locale Routines Keywords: See Also atof, localeconv, setlocale |
||||||
| Return Value strtod returns the value of the floating-point number, except when the representation would cause an overflow, in which case the function returns +/HUGE_VAL. The sign of HUGE_VAL matches the sign of the value that cannot be represented. strtod returns 0 if no conversion can be performed or an underflow occurs. strtol returns the value represented in the string nptr, except when the representation would cause an overflow, in which case it returns LONG_MAX or LONG_MIN. strtoul returns the converted value, if any, or ULONG_MAX on overflow. Each of these functions returns 0 if no conversion can be performed. wcstod, wcstol, and wcstoul return values analogously to strtod, strtol, and strtoul, respectively. For all six functions in this group, errno is set to ERANGE if overflow or underflow occurs. Parameters
|
||||||
|
Example #include <stdlib.h> void main( void ) string = -10110134932This
stopped it strtol = -2147483647 Stopped scan at: This stopped itstring
= 10110134932 |
|
strtod, wcstod
Remarks The strtod function converts nptr to a double-precision value. strtod stops reading the string nptr at the first character it cannot recognize as part of a number. This may be the terminating null character. wcstod is a wide-character version of strtod; its nptr argument is a wide-character string. Otherwise these functions behave identically. Generic-Text Routine Mappings
The LC_NUMERIC category setting of the current locale determines recognition of the radix character in nptr; for more information, see setlocale. If endptr is not NULL, a pointer to the character that stopped the scan is stored at the location pointed to by endptr. If no conversion can be performed (no valid digits were found or an invalid base was specified), the value of nptr is stored at the location pointed to by endptr. strtod expects nptr to point to a string of the following form: [whitespace] [sign] [digits] [.digits] [ {d | D | e | E}[sign]digits] A whitespace may consist of space and tab characters, which are ignored; sign is either plus (+) or minus (); and digits are one or more decimal digits. If no digits appear before the radix character, at least one must appear after the radix character. The decimal digits can be followed by an exponent, which consists of an introductory letter (d, D, e, or E) and an optionally signed integer. If neither an exponent part nor a radix character appears, a radix character is assumed to follow the last digit in the string. The first character that does not fit this form stops the scan. Subject: Data Conversion Routines | Floating-Point Support Routines | Locale Routines | strtod Functions Overview Keywords: See Also strtol, strtoul, atof, localeconv, setlocale |
|||||||||||||||||||||
| Return Value strtod returns the value of the floating-point number, except when the representation would cause an overflow, in which case the function returns +/HUGE_VAL. The sign of HUGE_VAL matches the sign of the value that cannot be represented. strtod returns 0 if no conversion can be performed or an underflow occurs. wcstod returns values analogously to strtod. For both functions, errno is set to ERANGE if overflow or underflow occurs. Parameters
|
|||||||||||||||||||||
|
Example #include <stdlib.h> void main( void ) string = -10110134932This
stopped it strtol = -2147483647 Stopped scan at: This stopped itstring
= 10110134932 |
|
_gcvt
Remarks The _gcvt function converts a floating-point value to a character string (which includes a decimal point and a possible sign byte) and stores the string in buffer. The buffer should be large enough to accommodate the converted value plus a terminating null character, which is appended automatically. If a buffer size of digits + 1 is used, the function overwrites the end of the buffer. This is because the converted string includes a decimal point and can contain sign and exponent information. There is no provision for overflow. _gcvt attempts to produce digits digits in decimal format. If it cannot, it produces digits digits in exponential format. Trailing zeros may be suppressed in the conversion. Subject: Data Conversion Routines | Floating-Point Support Routines Keywords: See Also atof, _ecvt, _fcvt |
||||||
| Return Value _gcvt returns a pointer to the string of digits. There is no error return. Parameters
|
||||||
|
Example #include <stdlib.h> void main( void ) |
|
sizeof Operator sizeof expression The sizeof keyword gives the amount of storage, in bytes, associated with a variable or a type (including aggregate types). When applied to a structure type or variable, sizeof returns the actual size, which may include padding bytes inserted for alignment. When applied to a statically dimensioned array, sizeof returns the size of the entire array. The sizeof operator cannot return the size of dynamically allocated arrays or external arrays. Keywords: For related information, see Operators. |
| The expression is either an identifier or a type-cast expression (a type specifier enclosed in parentheses). |
|
Example int array[] = { 1, 2, 3, 4,
5 }; // sizeof( array ) is 20 |
|
strtol, wcstol
Remarks The strtol function converts nptr to a long. strtol stops reading the string nptr at the first character it cannot recognize as part of a number. This may be the terminating null character, or it may be the first numeric character greater than or equal to base. wcstol is a wide-character version of strtol; its nptr argument is a wide-character string. Otherwise these functions behave identically. Generic-Text Routine Mappings
The current locale's LC_NUMERIC category setting determines recognition of the radix character in nptr; for more information, see setlocale. If endptr is not NULL, a pointer to the character that stopped the scan is stored at the location pointed to by endptr. If no conversion can be performed (no valid digits were found or an invalid base was specified), the value of nptr is stored at the location pointed to by endptr. strtol expects nptr to point to a string of the following form: [whitespace] [{+ | }] [0 [{ x | X }]] [digits] A whitespace may consist of space and tab characters, which are ignored; digits are one or more decimal digits. The first character that does not fit this form stops the scan. If base is between 2 and 36, then it is used as the base of the number. If base is 0, the initial characters of the string pointed to by nptr are used to determine the base. If the first character is 0 and the second character is not 'x' or 'X', the string is interpreted as an octal integer; otherwise, it is interpreted as a decimal number. If the first character is '0' and the second character is 'x' or 'X', the string is interpreted as a hexadecimal integer. If the first character is '1' through '9', the string is interpreted as a decimal integer. The letters 'a' through 'z' (or 'A' through 'Z') are assigned the values 10 through 35; only letters whose assigned values are less than base are permitted. Subject: Data Conversion Routines | Locale Routines | strtod Functions Overview Keywords: See Also strtod, strtoul, atof, localeconv, setlocale |
|||||||||||||||||||||
| Return Value strtol returns the value represented in the string nptr, except when the representation would cause an overflow, in which case it returns LONG_MAX or LONG_MIN. strtol returns 0 if no conversion can be performed. wcstol returns values analogously to strtol. For both functions, errno is set to ERANGE if overflow or underflow occurs. Parameters
|
|||||||||||||||||||||
|
Example #include <stdlib.h> void main( void ) string = -10110134932This
stopped it strtol = -2147483647 Stopped scan at: This stopped itstring
= 10110134932 |
|
_ultoa, _ultow
Remarks The _ultoa function converts value to a null-terminated character string and stores the result (up to 33 bytes) in string. No overflow checking is performed. radix specifies the base of value; radix must be in the range 2 36. _ultow is a wide-character version of _ultoa. Generic-Text Routine Mappings
Subject: Data Conversion Routines Keywords: See Also _itoa, _ltoa |
|||||||||||||||||||||
| Return Value Each of these functions returns a pointer to string. There is no error return. Parameters
|
|||||||||||||||||||||
|
Example #include <stdlib.h> void main( void ) _itoa( i, buffer, 10 ); _ltoa( l, buffer, 16 ); _ultoa( ul, buffer, 16 ); |
| Aktuelle Daten dieser Seite | Letzte Änderung: |
| |