wcstol - C wchar.h

C examples for wchar.h:wcstol

Type

function

From


<cwchar>
<wchar.h>

Description

Convert wide string to long integer

Prototype

long int wcstol (const wchar_t* str, wchar_t** endptr, int base);

Parameters

Parameter Description
str C wide string
endptr the next character in str after the numerical value.

Return Value

On success, it returns the converted integral number as a long int value.

For non valid conversion, a zero value is returned.

For out of range values, the function returns LONG_MAX or LONG_MIN defined in <climits>, and errno is set to ERANGE.

Demo Code


#include <wchar.h>

int main ()/*from w  w w.j  a  va 2s .  c o m*/
{
  wchar_t wsNumbers[] = L"2020 60c0c0 -1010101010101010101010 0x6fdead";

  wchar_t * pEnd;

  long int li1, li2, li3, li4;

  li1 = wcstol (wsNumbers,&pEnd,10);

  li2 = wcstol (pEnd,&pEnd,16);

  li3 = wcstol (pEnd,&pEnd,2);

  li4 = wcstol (pEnd,NULL,0);

  wprintf (L"%ld, %ld, %ld and %ld.\n", li1, li2, li3, li4);

  return 0;
}

Related Tutorials