C library functions -strtoul()

C Standard Library - <stdlib.h>

Description

C Library Functionsunsigned long int strtoul(const char *str, char **endptr, int base)Pass the parameterstrThe string pointed to, according to the givenbaseConverts to an unsigned long integer (of type unsigned long int). The 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)

Parameter

  • str-- The string to be converted to an unsigned long integer.
  • endptr-- A reference to an object of type char*, whose value is set by the function to the next character after the numeric value in str.
  • base-- The base, which must be between 2 and 36 (inclusive), or the special value 0.

Return Value

The function returns the converted long integer, or a zero value if no valid conversion could be performed.

Example

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

#include <stdio.h>
#include <stdlib.h>

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 us compile and run the above program, which will produce the following results:

数字(无符号长整数)是 2030300
字符串部分是 | This is test|

C Standard Library - <stdlib.h>

other extensions