data structure
this is c program to check balanced paranthesis using stack,
i dnt know whats wrong it always showing balanced expression.
tell me what i am doing wrong.??#include<stdio.h>
void main()
{
char stk[50],exp[100];
int top=-1,i;
printf("enter an expression\n");
gets(exp);
for(i=0;exp[i]!='\0';i++)
{
if(exp[i]=='('|| exp[i]=='['||exp[i]=='{')
{
top++;
stk[top]=exp[i];
}
else
if(exp[i]=')')
{
if(stk[top]=='(')
top--;
}
else
{
printf("unbalanced exp\n");
break;
}
if(exp[i]=']')
{
if(stk[top]=='[')
top--;
}
else
{
printf("unbalanced exp\n");
break;
}
if(exp[i]='}')
{
if(stk[top]=='{')
top--;
}
else
{
printf("unbalanced exp\n");
break;
}
}
if(top==-1)
printf("exp is balanced\n");
else
printf("exp is not balanced\n");
}