![]() |
![]() |
![]() |
Convert a string to a long integer
#include <stdlib.h> long atol( const char* ptr ); int64_t atoll( const char* nptr );
libc
The atol() function converts the string pointed to by ptr to a long integer; atoll() converts the string pointed to by nptr to an int64_t (long long) integer.
#include <stdlib.h> #include <stdio.h> int main( void ) { long x; x = atol( "-289" ); printf( "x = %d\n", x ); return EXIT_SUCCESS; }
produces the output:
x = -289
atol() is ANSI; atoll() is Unix
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | Yes |
Signal handler | Yes |
Thread | Yes |
atoi(), itoa(), ltoa(), sscanf(), strtol(), strtoul(), ultoa(), utoa()
![]() |
![]() |
![]() |