Hi, peeps. I was in the middle of ceatinga saved game feature to my game, when I ran into a problem. Is there a way to read a char and translate it to an int. Example "1" = 1. Is there a way to do this without annoying checks and case statements?
Hi, peeps. I was in the middle of ceatinga saved game feature to my game, when I ran into a problem. Is there a way to read a char and translate it to an int. Example "1" = 1. Is there a way to do this without annoying checks and case statements?
"If you tell the truth, you don't have to remember anything"
-Mark Twain
char c='1';
int i = c-'0';
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
I don't get it.
"If you tell the truth, you don't have to remember anything"
-Mark Twain
__________________
"If you tell the truth, you don't have to remember anything"
-Mark Twain
If you don't remember anything, you don't have to tell the truth
-L. Obotomy
Subtract the ASCII value of zero from the ASCII value of the character. Since the chars are stored as ASCII codes anyway, just subtract '0'
from your character to convert.