Syntax
#include <wchar.h> long int wcstol(const wchar_t *nptr, wchar_t **endptr, int base);Description
wcstol converts the wide-character string pointed to by nptr to a long integer value. nptr points to a sequence of wide characters that can be interpreted as a numerical value of type long int. wcstol stops reading the string at the first wide character that it cannot recognize as part of a number. This character can be the wchar_t null character at the end of the string. The ending character can also be the first numeric character greater than or equal to the base.
When you use wcstol, nptr should point to a string with the following
form: ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ ³
³ >>ÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÂÄÄÄÂÄÄÂÄÄÄÄÂÄÄÂÄÄÄÄÄÄÄÄÂÄÄ><
³
³ ÀÄwhite-spaceÄÙ ÃÄ+Ä´ ÃÄ0ÄÄ´ ÀÄdigitsÄÙ ³
³ ÀÄÁÄÙ ÃÄ0xÄ´ ³
³ ÀÄ0XÄÙ ³
³ ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
If base is in the range of 2 through 36, it becomes the base of the number. If base is 0, the prefix determines the base (8, 16, or 10): the prefix 0 means base 8 (octal); the prefix 0x or 0X means base 16 (hexadecimal); using any other digit without a prefix means decimal.
The behavior of wcstol is affected by the LC_CTYPE category of the current locale.
wcstol returns the converted long integer value. If no conversion could be performed, wcstol returns 0. If the correct value is outside the range of representable values, wcstol returns LONG_MAX or LONG_MIN returned (according to the sign of the value), and sets errno to ERANGE.
If the string nptr points to is empty or does not have the expected form, no conversion is performed, and the value of nptr is stored in the object pointed to by endptr, provided that endptr is not a null pointer.
This example uses wcstol to convert the wide-character string wcs to a long integer value.
#include <stdio.h> #include <wchar.h> int main(void) { wchar_t *wcs = L"10110134932"; wchar_t *stopwcs; long l; int base; printf("wcs = \"%ls\"\n", wcs); for (base=2; base<=8; base*=2) { l = wcstol(wcs, &stopwcs, base); printf(" wcstol = %ld\n" " Stopped scan at \"%ls\"\n\n", l, stopwcs); } return 0; /**************************************************************************** The output should be similar to : wcs = "10110134932" wcstol = 45 Stopped scan at "34932" wcstol = 4423 Stopped scan at "4932" wcstol = 2134108 Stopped scan at "932" ****************************************************************************/ }Related Information