Share via


_wtoi, _wtoi64, _wtol

Converts a wide-character string to an integer (_wtoi and _wtoi64) or to a long integer (_wtol).

int_wtoi(constwchar_t*string);

__int64_wtoi64(wchar_t*string);

long_wtol(constwchar_t*string);

Routine Required Header Compatibility
_wtoi <stdlib.h> or <wchar.h> Win 95, Win NT
_wtoi64 <stdlib.h> or <wchar.h> Win 95, Win NT
_wtol <stdlib.h> or <wchar.h> Win 95, Win NT

For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version

Return Value

Each function returns the int, __int64, or long value produced by interpreting the input characters as a number. If the input cannot be converted to a value of the appropriate type, _wtoi and _wtoi64 return 0 and _wtol returns 0L. The return value is undefined in case of overflow.

Parameter

string

String to be converted

Remarks

The _wtoi and _wtoi64 function converts a wide-character string to an integer value. _wtol converts a wide-character string to a long integer value. 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 of the current locale. (For more information on the LC_NUMERIC category, see setlocale.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 (L'\0') terminating the string.

The string argument for these functions has the form

[whitespace] [sign]digits

A whitespace consists of space and/or tab characters, which are ignored. sign is either plus (+) or minus ( ). digits is one or more decimal digits. _wtoi, _wtoi64, and _wtol do not recognize decimal points or exponents.

Example

/* ATOF.C: This program shows how numbers stored
 * as strings can be converted to numeric values
 * using the atof, atoi, and atol functions.
 */

#include <stdlib.h>
#include <stdio.h>

void main( void )
{
   char *s; double x; int i; long l;

   s = "  -2309.12E-15";    /* Test of atof */
   x = atof( s );
   printf( "atof test: ASCII string: %s\tfloat:  %e\n", s, x );

   s = "7.8912654773d210";  /* Test of atof */
   x = atof( s );
   printf( "atof test: ASCII string: %s\tfloat:  %e\n", s, x );

   s = "  -9885 pigs";      /* Test of atoi */
   i = atoi( s );
   printf( "atoi test: ASCII string: %s\t\tinteger: %d\n", s, i );

   s = "98854 dollars";     /* Test of atol */
   l = atol( s );
   printf( "atol test: ASCII string: %s\t\tlong: %ld\n", s, l );
}

Output

atof test: ASCII string:   -2309.12E-15   float:  -2.309120e-012
atof test: ASCII string: 7.8912654773d210   float:  7.891265e+210
atoi test: ASCII string:   -9885 pigs      integer: -9885
atol test: ASCII string: 98854 dollars      long: 98854

Data Conversion RoutinesLocale Routines

See Also   atoi, _ecvt, _fcvt, _gcvt