I'm new to c and am writing a switch function that whenever the passed in string is ), }, ], it returns false when the popped out expression isn't the matching open parentheses. (yes, it's the balanced parentheses problem...)
I can be sure that the segmentation fault only comes from this switch statement, and the code works perfectly fine without it.
my code is:
switch (expr[i])
{
case ')': if (pop(&Stack) == '{' || pop(&Stack) =='[') {
return 0;}
break;
case '}': if (pop(&Stack) == '(' || pop(&Stack) =='[') {
return 0; }
break;
case ']': if (pop(&Stack) == '{' || pop(&Stack) =='(') {
return 0; }
break;
}
It gives me "Segmentation fault: 11".