Initializacia

This commit is contained in:
Anton 2024-10-29 17:55:12 +01:00
parent 647c26db9a
commit 2fa7918d0b
2 changed files with 17 additions and 2 deletions

BIN
a1/main

Binary file not shown.

View File

@ -26,6 +26,16 @@ char matching_bracket(char ch) {
}
}
char expected_closing(char ch) {
switch (ch) {
case '(': return ')';
case '{': return '}';
case '[': return ']';
case '<': return '>';
default: return 0;
}
}
void check_brackets(const char *line) {
StackItem stack[MAX_LEN];
int stack_top = -1;
@ -51,14 +61,19 @@ void check_brackets(const char *line) {
stack_top--;
} else {
printf("Crossed bracket %c in %d, expected %c\n", ch, i,
matching_bracket(stack[stack_top].bracket));
expected_closing(stack[stack_top].bracket));
return;
}
}
}
if (stack_top >= 0) {
printf("Unmatched bracket %c in %d\n", stack[stack_top].bracket, stack[stack_top].position);
printf("Missing closing brackets:");
while (stack_top >= 0) {
printf(" %c", expected_closing(stack[stack_top].bracket));
stack_top--;
}
printf("\n");
} else {
printf("All brackets OK\n");
}