Using atoi() C function to convert a string to 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 an integer value using atoi() C function
To show: How to use atoi() C function in converting a given string to an integer
// Using atoi()_atoi64()/_wtoi()/_wtoi64() - converting string to integer
#include <stdio.h>
int main(void)
{
int i;
i = atoi("1234");
printf("Using atoi() - converting string to integer\n");
printf("-------------------------------------------\n\n");
printf("The string \"1234\" converted to int is %d\n", i);
printf("The converted value %d minus 123 is %d\n", i, i - 123);
return 0;
}
Output example:
Using atoi() - converting string to integer
-------------------------------------------
The string "1234" converted to int is 1234
The converted value 1234 minus 123 is 1111
Press any key to continue . . .