Update a1/program.c

This commit is contained in:
Viktor Daniv 2024-10-26 19:50:02 +00:00
parent ba66ca38db
commit c3c2e52c68

View File

@ -35,13 +35,13 @@ void check_brackets(const char *code) {
// Якщо закрита дужка
else if (c == ')' || c == '}' || c == ']' || c == '>') {
if (stack_top < 0) {
printf("Unexpected closing bracket %c in %d\n", c, i);
printf("Unexpected closing bracket %c at position %d\n", c, i);
return;
}
char top = stack[stack_top--];
char expected = expected_close(top);
if (expected != c) {
printf("Crossed bracket %c in %d, expected %c\n", c, i, expected);
printf("Crossed bracket %c at position %d, expected %c\n", c, i, expected);
return;
}
}
@ -49,7 +49,11 @@ void check_brackets(const char *code) {
// Перевірка, чи всі дужки закриті
if (stack_top >= 0) {
printf("Missing closing brackets: %c\n", expected_close(stack[stack_top]));
printf("Missing closing brackets: ");
while (stack_top >= 0) {
printf("%c", expected_close(stack[stack_top--]));
}
printf("\n");
} else {
printf("All brackets OK\n");
}
@ -67,4 +71,4 @@ int main() {
check_brackets(code);
return 0;
}
}