diff --git a/a1/program.c b/a1/program.c index 5823a0e..ba05f81 100644 --- a/a1/program.c +++ b/a1/program.c @@ -16,6 +16,14 @@ int isMatching(char open, char close) { (open == '<' && close == '>'); } +char expectedClosing(char open) { + if (open == '{') return '}'; + if (open == '[') return ']'; + if (open == '(') return ')'; + if (open == '<') return '>'; + return '\0'; +} + int main() { char input[101]; char stack[100]; @@ -54,8 +62,9 @@ int main() { } if (top != -1) { - printf("Missing closing brackets: %c\n", stack[top]); - return 0; + char expected = expectedClosing(stack[top]); + printf("Missing closing brackets: %c\n", expected); + return 1; } printf("All brackets OK\n");