wstrtol, watol, or watoi Subroutine

Purpose

Converts a string to an integer.

Library

Standard C Library (libc.a)

Syntax

#include <wstring.h>

long wstrtol ( String,  Pointer,  Base)
wchar_t *String, **Pointer;
int Base;

long watol (String)
wchar_t *String;
int watoi (String)
wchar_t *String;

Description

The wstrtol subroutine returns a long integer that is converted from the string pointed to by the String parameter. The string is searched until a character is found that is inconsistent with Base. Leading white-space characters defined by the ctype subroutine iswspace are ignored.

When the value of Pointer is not (wchar_t **) null, a pointer to the terminating character is returned to the address indicated by Pointer. When an integer cannot be created, the address indicated by Pointer is set to String, and 0 is returned.

When the value of Base is positive and not greater than 36, that value is used as the base during conversion. Leading zeros that follow an optional leading sign are ignored. When the value of Base is 16, 0x and 0X are ignored.

When the value of Base is 0, the system chooses an appropriate base after examining the actual string. An optional sign followed by a leading zero signifies octal, and a leading 0x or 0X signifies hexadecimal. In all other cases, the subroutines assume a decimal base.

Truncation from long data type to int data type occurs by assignment, and also by explicit casting.

The watol (String) subroutine functions like wstrtol (String, (wchar_t **) null, 10).

The watoi (String) subroutine functions like (int) wstrtol (String, (wchar_t **) null, 10).

Note: Even if overflow occurs, it is ignored.

Parameters

Item Description
String Specifies the address of the string to scan.
Pointer Specifies the address at which the pointer to the terminating character is stored.
Base Specifies an integer value used as the base during conversion.