This shows you the differences between two versions of the page.
— |
c:stdlib.h:atol [2024/02/16 01:04] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | |||
+ | |||
+ | {{keywords>wiki library source code example reference}} | ||
+ | ====== atol ====== | ||
+ | <code c> | ||
+ | #include <stdlib.h> | ||
+ | long int atol(const char *str); | ||
+ | </code> | ||
+ | convert a string to long integer | ||
+ | |||
+ | ===== C Sourcecode Example ===== | ||
+ | <code c> | ||
+ | #include <stdio.h> /* including standard library */ | ||
+ | //#include <windows.h> /* uncomment this for Windows */ | ||
+ | |||
+ | #include <stdlib.h> | ||
+ | |||
+ | int main(void){ | ||
+ | |||
+ | char string[]="1234"; | ||
+ | long int i; | ||
+ | |||
+ | printf("string = %s \n", string ); | ||
+ | printf("int = %li \n", atol(string) ); | ||
+ | |||
+ | i = atol(string); | ||
+ | i = i + i; | ||
+ | printf("i + i = %li\n", i); | ||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | |||
+ | </code> | ||
+ | |||
+ | ==== Output ==== | ||
+ | |||
+ | Output: | ||
+ | user@host:~$ ./atol | ||
+ | string = 1234 | ||
+ | int = 1234 | ||
+ | i + i = 2468 | ||
+ | |||
+ | |||