In C/C++ char type is an integral (i.e. integer) type. You can add/subtract chars as integers, for example:
Code:
char ch = '2';
int n;
...
n = ch - '0'; /* n == 2 now */
Be careful: there are three char types in these languages:
1. signed char
2. unsigned char
3. char /* as is: may be treated as signed or unsigned */
For ANSI codes (0..127) is no matter what's a simple char treatment in the implementation. You may use explicit cast to (unsigned char) in proper cases (more portability)...
I think what you're talking about refers more specifically to this. If the user inputs a string (in an editbox) that is "1234", to get the actual integer value, use the function atoi(). That converts a character string to an integer.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.