Update a1/program.c

This commit is contained in:
Yurii Chechur 2024-10-24 20:37:59 +00:00
parent 8bf0959328
commit 7d962d4d38

View File

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