Initializacia
This commit is contained in:
parent
647c26db9a
commit
2fa7918d0b
19
a1/program.c
19
a1/program.c
@ -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");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user