Function strtoul () in C

The unsigned function long int strtoul (const char * str, char ** endptr, int base) in Standard C library converts part of the original string in str to a value of long int corresponding to the base base, given can be 2, 8, ., 36, or special value 0.

Declaring the function strtoul () in C

Below is the declaration for strtoul () in C:

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

Parameters

str - This is a string representing an integer.

endptr - This is a reference to a allocated object of type char *, whose value is set by the function to the next character in str after the numeric value.

base - This is the base, must be 2, 8, ., 36, or special value 0.

Returns the value

This function returns an integer that has been converted as a long int value. Otherwise, the function returns 0.

For example

The following program C illustrates the usage of the strtoul () function in C:

 #include #include int main () { char str [ 30 ] = "21.32301 Hoc C tai QTM" ; char * ptr ; long ret ; ret = strtoul ( str , & ptr , 10 ); printf ( "Phan gia tri (unsigned long int) la: %lun" , ret ); printf ( "Phan gia tri chuoi la |%s|" , ptr ); return ( 0 ); } 

Compile and run the above C program to see the results.

According to Tutorialspoint

Previous article: Function strtol () in C

Next lesson: Calloc () function in C

4 ★ | 1 Vote

May be interested

  • Calloc () function in CPhoto of Calloc () function in C
    the function void * calloc (so-phan-tu, kich-co-phan-tu) allocates the requested memory and returns a pointer to it. the difference between malloc and calloc is: malloc does not set memory to 0 while calloc sets the allocated memory to 0.
  • Free () function in CPhoto of Free () function in C
    the void free function (void * ptr) frees the previously allocated memory by a call to calloc, malloc, or realloc
  • Malloc () function in CPhoto of Malloc () function in C
    the malloc () function allocates the requested memory and returns a pointer to it.
  • Function realloc () in CPhoto of Function realloc () in C
    the realloc () function attempts to recover the memory block pointed to by the ptr pointer that was previously allocated with a call to malloc or calloc.
  • The abort () function in CPhoto of The abort () function in C
    the abort () function stops executing the program abnormally.
  • The function atexit () in CPhoto of The function atexit () in C
    int atexit function (void (* func) (void)) calls function func when the program ends. you can register your end function (func function) wherever you like, but this function will be called at the end of the program.