Or! if you REALLY wanted to be creative (which I am all about)
Example:
Code:
typedef float (*operation)(float, float);
float add(float a, float b) { return a + b; }
float sub(float a, float b) { return a - b; }
float mul(float a, float b) { return a * b; }
float div(float a, float b) { return a / b; }
operation isoperator(int c)
{
switch(c)
{
case '+': return add;
case '-': return sub;
case '*': return mul;
case '/': return div;
default: return 0;
}
}
/* Then in your for loop */
for(i = 0; i < strlen(input); ++i)
{
operation op = isoperator(input[i]);
if(op)
push((&stk), (*op)(pop(&stk),pop(&stk)));
else if(isdigit(input[i]))
push(&stk, (input[i] - '0'));
}
Viola.