So I want to take a string in such as 8302 and convert this into an integer by creating my own function and not using the stoi/atoi functions.
I tried so far by doing:
int stringToInt(string input)
{
int i = 0;
while(input[i] >= '0' && input[i] <= '9')
{
input[i] = input[i] * 10 + ......
i++;
}
return i;
}
I know i need to keep multiplying by 10 everytime i find an integer so i can increase it e.g 123 = 1*10*10+2*10+3. but i dont know how to code this. could anyone suggest a method?