C examples for wchar.h:wcstol
function
<cwchar> <wchar.h>
Convert wide string to long integer
long int wcstol (const wchar_t* str, wchar_t** endptr, int base);
Parameter | Description |
---|---|
str | C wide string |
endptr | the next character in str after the numerical 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.
#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; }