Use strtoul to convert string to unsigned long

Syntax

C strtoul function has the following format.

unsigned long int strtoul(const char *start, char **end, int radix);

C strtoul function is from header stdlib.h.

Description

C strtoul function converts the string into an unsigned long int according to the base of the number.

If radix is zero, the base is determined by the rules that govern constant specification. If the radix is specified, it must be in the range 2 through 36.

Example

Convert string to unsigned long using C strtoul function.


#include <stdlib.h>
//from w  ww.  j  a v a  2  s.  co  m
int main(void){

    char *start, *end;
    char a[100];

    end = a;
    *start= "12341234";
    printf("%d", strtoul(start, &end, 8));

}

The code above generates the following result.





















Home »
  C Language »
    Function Reference »




assert.h
ctype.h
math.h
setjmp.h
signal.h
stdio.h
stdlib.h
string.h
time.h
wctype.h