Using atol() C function to convert a string to a long integer
Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows 2003 Server Standard Edition
Header file: Standard
Additional library: none/default
Additional project setting: Set project to be compiled as C
Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C Code (/TC)
Other info:
To do: Converting a string to long integer value using atol() C function
To show: How to use atol() C function in converting a string to a long integer value
// Using atol()/_wtol() - converting string to long
#include <stdio.h>
int main(void)
{
long newlong;
newlong = atol("123456");
printf("Using atol() - converting string to long\n");
printf("----------------------------------------\n\n");
printf("The string \"123456\" converted to long int is %ld\n", newlong);
printf("The converted value, %ld divided by 2 is %ld\n", newlong, newlong / 2);
return 0;
}
Output example:
Using atol() - converting string to long
----------------------------------------
The string "123456" converted to long int is 123456
The converted value, 123456 divided by 2 is 61728
Press any key to continue . . .