From 7d962d4d38d5dadf0686c2be08ed49aafa5fda74 Mon Sep 17 00:00:00 2001 From: Yurii Chechur Date: Thu, 24 Oct 2024 20:37:59 +0000 Subject: [PATCH] Update a1/program.c --- a1/program.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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");