if(isalnum(ch))
You should #include <ctype.h>
if you use isalnum
.
while(token=pop(&s)!='(')
The comparison operators have precedence over the assignment operator, which means that here you are comparing pop(&s)!='('
and then assign the result (0
or 1
) to token
. The comparison will still work and the loop behave correctly, but the character in token
will be some control character, rather than a letter.
Use correct parentheses:
while((token=pop(&s))!='(')
Your function int priority(char ch)
does not have a return statement for every possible input. You should add a final return statement to catch these cases (even if they should not happen)
Also much of your code is too verbose without need. For example:
char pop(stack* s)
{
char ch;
ch=s->data[s->top];
s->top=s->top-1;
return ch;
}
is the same as:
char pop(stack* s)
{
s->top--;
return s->data[s->top+1];
}
or
int empty(stack* s)
{
if(s->top==-1)
return 1;
return 0;
}
is the same as
int empty(stack* s)
{
return s->top == -1;
}