_wtoi, _wtol (Windows CE 5.0)

Send Feedback

Developing an Application > Microsoft C Run-time Library for Windows CE > Run-time Library Reference

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

int _wtoi( const wchar_t *string );int _wtol( const wchar_t *string );

Parameters

  • string
    String to be converted.

Return Values

This 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, the function returns 0. The return value is undefined in case of overflow.

Remarks

These functions are supported by all versions of the C run-time libraries.

The _wtoi function converts a wide-character string to an integer value.

The _wtol function 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.

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 this function 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 and _wtol do not recognize decimal points or exponents.

Example

Description

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

Code

#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

Requirements

OS Versions: Windows CE 2.0 and later.

Header: stdio.h, stdlib.h.

Link Library: coredll.dll.

See Also

atoi | _ecvt | _fcvt | _gcvt

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.