The logic should be like this :
while ( input != 13 )
{
if input is '(' or '{' or '[' or ')' or '}' or ']'
{
if input is '(' or '{' or '['
push it into the stack.
else if input is ')' or '}' or ']'
{
if stack is empty
report error.
pop cell from stack
if cell "matches input"
we are ok.
else if cell dont "matches input" or stack is empty
report error.
}
}
}
if the stack is not empty
report error.
Also I would suggest replacing your input function
with fgets.
A nice touch would be to add to the switch statment
a default case, checking if it is a number of math experssion.
Don't ever write code like this :
free(top);
top=top->next; Once you free(p), dont access it !!!!!!!!!!
It will probaly work, but its wrong, and
also your grade will be like it.