I am having a problem with atoi() in this function. It works correctly in Windows, putting a shiftAmount that corresponds to the two digits, but fails under Linux/UNIX where, for example, a 2 and a 3 get made into 20 + 32 = 52 instead of 20 + 3 = 23. What's wrong? Is it because I declared my variables sequentially and byte order is reversed in memory so that passing by reference to atoi(), the second call picks up both digits in reverse order? How do I fix this?
Code:
void convertTwoDigits(char firstDigit, char secondDigit, int& shiftAmount, bool& errorFlag)
{
if(isdigit(firstDigit))
{
shiftAmount = atoi(&firstDigit);
cout << shiftAmount << "\n";
if(isdigit(secondDigit))
{
shiftAmount *= 10;
shiftAmount += atoi(&secondDigit);
}
}
else
{
displayErrorMessage(1);
errorFlag = true;
}
if(shiftAmount > 26)
{
displayErrorMessage(2);
errorFlag = true;
}
}