The strtoul() function in C/C++ which converts the initial part of the string in str to an unsigned long int value according to the given base, which must be between 2 and 36 inclusive, or be the special value 0. This function discard any white space characters until the first non-whitespace character is found, then takes as many characters as possible to form a valid base-n unsigned integer number representation and converts them to an integer value.
unsigned long int strtoul(const char *str, char **end, int base)
Parameter: The function accepts three mandatory parameters which are described below:
- str: Pointer to the null-terminated byte string to be interpreted
- end : Pointer to a pointer to character (Reference to an object of type char*)
- base : Base of the interpreted integer value
Return value: The function returns two value as below:
- On success, it returns an integer value corresponding to the contents of str.
- If no valid conversion is done, then 0 is returned.
Below programs illustrate the above function:
The unsigned long integer is : 15124320 String in str is : Geeks For Geeks
The unsigned long integer is : 12345 String in str is : GFG The unsigned long integer is : 24677 String in str is : GFG The unsigned long integer is : 866825 String in str is : GFG
- Function Overloading vs Function Overriding in C++
- What happens when a virtual function is called inside a non-virtual function in C++
- div() function in C++
- fma() function in C++
- log() function in C++
- exp() function C++
- wcstoul() function in C/C++
- bitset all() function in C++ STL
- towctrans() function in C/C++
- iswcntrl() function in C/C++
- atan2() function in C++ STL
- wmemcmp() function in C/C++
- mktime() function in C++ STL
- bitset set() function in C++ STL
- wcrtomb() function in C/C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.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.