I'm trying to parse out mathematical equation from given char array, for example char equation[255] = "4+4";
and I want to copy first number to long number1
, operator to char oper
and second number to long number2
.
I've tried sscanf(equation, "%d%c%d", &number1, &oper, &number2);
but it just gets first number and fails to extract operator and second number.
Tried this method:
while (isdigit(equation[k]))
{
k++;
}
oper = equation[k];
and still it doesn't get the operator. Is there more simple way to parse out equation in c++?