The atol () function in C
The function long int atol (const char * str) in the standard C library converts a string pointed to by parameter str to some long int.
The function long int atol (const char * str) in the standard C library converts a string pointed to by parameter str to some long int.
Declare atol () function in C
Below is the declaration for the atol () function in C:
long int atol ( const char * str )
Parameters
str - This is a string representing an integer.
Returns the value
This function returns an integer that has been converted as a long int value. If no valid conversion is performed, the function returns 0.
For example
The following program C illustrates the usage of the atol () function in C:
#include #include #include int main () { long val ; char str [ 20 ]; strcpy ( str , "98993489" ); val = atol ( str ); printf ( "Gia tri duoi dang chuoi = %s, nGia tri duoi dang long int = %ldn" , str , val ); strcpy ( str , "QTM.com" ); val = atol ( str ); printf ( "nGia tri duoi dang chuoi = %s, nGia tri duoi dang long int = %ldn" , str , val ); return ( 0 ); } Compile and run the above C program to see the results.
According to Tutorialspoint
Previous lesson: Function atoi () in C
Next article: Function strtod () in C
Discover more
C program operation string in C parameter in CShare by
Marvin Fry
Update 25 May 2019
You should read it
- Function strtoul () in C
- Function strtol () in C
- Atof () function in C
- The memchr () function in C
- The function gets () in C
- The Quiet Details That Make a Sports Betting Platform Feel Reliable
- Instructions on creating toy set images with ChatGPT AI
- How are AI agents changing the journalism industry?
- The function strtod () in C
- Function strtol () in C
- Function strtoul () in C