Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C Library Function - strtoul()

C Library Function - strtoul()

C Standard Library - <stdlib.h> C Standard Library -

Description

C Library Function **unsigned long int strtoul(const char *str, char endptr, int base) Converts the string pointed to by the argument str converts the string pointed to by base into an unsigned long integer (of type unsigned long int); base must be between 2 and 36 (inclusive), or the special value 0.

Declaration

Below is the declaration of the strtoul() function.



unsigned long int strtoul(const char *str, char **endptr, int base)

Parameters

Return Value

This function returns the converted long integer; if no valid conversion was performed, a zero value is returned.

Example

The following example demonstrates the use of the strtoul() function.



#include 

#include 



int main()

{

   char str[30] = "2030300 This is test";

   char *ptr;

   long ret;



   ret = strtoul(str, &ptr, 10);

   printf("数字(无符号长整数)是 %lu\n", ret);

   printf("字符串部分是 |%s|", ptr);



   return(0);

}

Let's compile and run the above program, which will produce the following result:



数字(无符号长整数)是 2030300

字符串部分是 | This is test|

C Standard Library - <stdlib.h> C Standard Library -