Converting ascii to integer without using atoi
very simple question, but I'm having a problem doing this. I simply need to take a string, "342" and instead of its ascii range, I need to change it to an integer of 342.
I think I need to take its ascii value and subtract that from the ascii value of 0. This is what I have so far:
Code:
int count1
int pos
char string
count1 = 0
pos = 0
cin >> string
for (pos != '\0', pos++)
string[pos] = count1
count1 = count1*10 + (pos - '0');
I remember our teacher going over this, but I can't get ahold of him right now. This is the best I can remember, and I KNOW its wrong. I appreciate the help.