I'm trying to change a char to an int using the stdlib.h atoi function
It works perfectly on windows using VC++ however on Ubuntu
Linux using g++ the value of t is off and from is correct.
char from = '0', to = '0';
cout<< "From: ";
cin >> from;
cout<<"To: ";
cin>> to;
//from within range 0-7 to in range 0-6
if( ((int)from >= 48 && (int)from <= 55) &&
((int)from >= 48 && (int)to <= 54) )
{
int f = atoi(&from);
int t = atoi(&to);
someFunc(f,t);
}
For example when i input
from = 2 which is 50
to = 6 which is 54
f=2
t=62
This appears to be adding from and to together 50 + 54
and the using atoi on that then uses atoi on to on its own and
adds them together
50 + 54 = 104
104 -48 = 56 + 6 = 62
On a few different tests it seems to follow this pattern
My question is why is this happening using g++ and not VC++