As it stands, your calculator recognizes a single digit as operand while it would need to recognize a number (multiple digits). That means you must allow a separator in your input expression (otherwise it wouldn't be able to distinguish between two input numbers), you have to handle it and, finally, you need to handle multiple digits as a single token (a number, the operand).
I have modified you code in order to work with such requirements.
You may input expressions like:
43 18 + 4 *
#include <stdio.h>
#include <math.h>
#define MAX 20
struct stack
{
int top;
float str[MAX];
} s;
char postfix[MAX];
int operand;
void push(float);
float pop();
int isoperand(int n);
int get_operand(int n);
int skip_blanks(int n);
float operate(float,float,char);
int main()
{
int i=0;
printf("Enter Expression:");
fgets(postfix, sizeof(postfix), stdin);
float ans,op1,op2;
while(1)
{
i = skip_blanks(i);
if ( postfix[i] == '\n')
break;
else if(isoperand(i))
{
i = get_operand(i);
push(operand);
}
else
{
op1=pop();
op2=pop();
ans=operate(op1,op2, postfix[i]);
push(ans);
printf("%f %c %f = %f\n",op2,postfix[i],op1,ans);
i++;
}
}
printf("%f",s.str[s.top]);
getchar();
return 0;
}
int skip_blanks(int n)
{
while (postfix[n] == ' ') n++;
return n;
}
int get_operand(int n)
{
operand = 0;
while (postfix[n] >= '0' && postfix[n] <= '9')
{
operand *= 10;
operand += postfix[n]-'0';
n++;
}
return n;
}
int isoperand(int i)
{
char x = postfix[i];
if(x>='0' && x<='9')
return 1;
else
return 0;
}
void push(float x)
{
if(s.top==MAX-1)
printf("Stack is full\nStack overflow\n");
else
{
s.top++;
s.str[s.top]=x;
}
}
float pop()
{
if(s.top==-1)
{
printf("Stack is emplty\nSTACK UNDERFLOW\n");
getchar();
return nan("?");
}
else
{
s.top--;
return s.str[s.top+1];
}
}
float operate(float op1,float op2,char a)
{
switch(a)
{
case '+':return op2+op1;
case '-':return op2-op1;
case '*':return op2*op1;
case '/':return op2/op1;
case '^':return pow(op2,op1);
}
return nan("?");
}