Function strtol () in C
The function long int strtol (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, but must are 2, 8, ., 36, or special value 0.
Declaring the function strtol () in C
Below is the declaration for strtol () in C:
long int strtol ( 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 strtol () function in C:
#include #include int main () { char str [ 30 ] = "21.32301 Hoc C tai QTM" ; char * ptr ; long ret ; ret = strtol ( str , & ptr , 10 ); printf ( "Phan gia tri so (unsigned long int) la: %ldn" , ret ); printf ( "Phan chuoi la: |%s|" , ptr ); return ( 0 ); }
Compile and run the above C program to see the results.
According to Tutorialspoint
Previous article: Function strtod () in C
Next lesson: Function strtoul () in C
You should read it
- The function atoi () in C
- The atol () function in C
- The function strtod () in C
- Function strtoul () in C
- Atof () function in C
- The memchr () function in C
- The function gets () in C
- Function fputs () in C
- The getchar () function in C
- The function vsprintf () in C
- Putchar () function in C
- The abort () function in C
Maybe you are interested
How to Integrate ChatGPT for Siri on iPhone
How to get data from web into Excel
Top best apps to turn men into women, boys into girls
How to blur background images in PowerPoint - Adjust background image display mode
Instructions for creating PowerPoint background color effects - Create a new background for slides
7 Best Pinterest Alternatives