wcstoul() function in C/C++
The wcstoul() function in C/C++ convert wide string to unsigned long integer.
This function sets a pointer to point to the first character after the last valid character of the wide string if there is any, otherwise, the pointer is set to null. This function ignores all the leading whitespace characters until the primary non-whitespace character is found.
Syntax:
unsigned long wcstoul( const wchar_t* string, wchar_t** endString, int base )
Parameters: The function accepts three mandatory parameters which are described below:
- string: specifies the string containing the representation of an integral number.
- endString: specifies the value of endString is set by the function to the next character in string after the last valid character.
- base: specifies the set of valid values for base is {0, 2, 3, …, 35, 36}.
Return value : The function returns two value as below:
- On success, the function returns the converted integral number as an unsigned long int value.
- returns zero, if no valid conversion takes place.
Below programs illustrate the above function:
Program 1:
// C++ program to illustrate // wcstoul() function // with base equal to 36 #include <bits/stdc++.h> using namespace std; int main() { // initialize the wide string wchar_t string[] = L "999gfg" ; // set a pointer ponting // the string at the end wchar_t * endString; // print the unsigned long integer value // with the end string // initialize the base as 36 unsigned long value = wcstoul(string, &endString, 36); wcout << L "String value given is -> " << string << endl; wcout << L "Unsigned Long Int value will be -> " << value << endl; wcout << L "End String will be-> " << endString << endl; return 0; } |
String value given is -> 999gfg Unsigned Long Int value will be -> 559753324 End String will be->
Program 2:
// C++ program to illustrate // wcstoul() function // with different bases #include <bits/stdc++.h> using namespace std; int main() { // initialize the wide string wchar_t string[] = L "99999999999gfg" ; // set a pointer ponting // the string at the end wchar_t * endString; // print the unsigned long integer value with // the end string with base 36 long value = wcstol(string, &endString, 35); wcout << L "String value --> " << string << "\n" ; wcout << L "Long integer value --> " << value << "\n" ; wcout << L "End String = " << endString << "\n" ; // print the unsigned long integer value with // the end string with base 16 value = wcstol(string, &endString, 16); wcout << L "String value --> " << string << "\n" ; wcout << L "Long integer value --> " << value << "\n" ; wcout << L "End String = " << endString << "\n" ; // print the unsigned long integer value with // the end string with base 12 value = wcstol(string, &endString, 12); wcout << L "String value --> " << string << "\n" ; wcout << L "Long integer value --> " << value << "\n" ; wcout << L "End String = " << endString << "\n" ; return 0; } |
String value --> 99999999999gfg Long integer value --> 9223372036854775807 End String = String value --> 99999999999gfg Long integer value --> 10555311626649 End String = gfg String value --> 99999999999gfg Long integer value --> 607915939653 End String = gfg
Recommended Posts:
- Function Overloading vs Function Overriding in C++
- What happens when a virtual function is called inside a non-virtual function in C++
- fma() function in C++
- exp() function C++
- log() function in C++
- div() function in C++
- arc function in C
- regex_iterator() function in C++ STL
- putchar() function in C
- Inline function in C
- map key_comp() function in C++ STL
- strol() function in C++
- unordered_map end( ) function in C++ STL
- strcspn() function in C/C++
- array at() function in C++ STL
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.