Update a1/program.c
This commit is contained in:
parent
ce85b8fd29
commit
4fde67b65b
19
a1/program.c
19
a1/program.c
@ -29,7 +29,6 @@ int main() {
|
|||||||
char stack[100];
|
char stack[100];
|
||||||
int top = -1;
|
int top = -1;
|
||||||
|
|
||||||
// printf("");
|
|
||||||
fgets(input, 101, stdin);
|
fgets(input, 101, stdin);
|
||||||
|
|
||||||
printf("Read: %s", input);
|
printf("Read: %s", input);
|
||||||
@ -46,24 +45,24 @@ int main() {
|
|||||||
}
|
}
|
||||||
} else if (isClosing(current)) {
|
} else if (isClosing(current)) {
|
||||||
if (top == -1) {
|
if (top == -1) {
|
||||||
printf("Unexpected closing bracket %c in %d\n", current, i);
|
printf("Unexpected closing bracket %c at position %d\n", current, i);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (!isMatching(stack[top], current)) {
|
if (!isMatching(stack[top], current)) {
|
||||||
printf("Crossed bracket '%c' in %d , expected \n", current, i);
|
char expected = expectedClosing(stack[top]);
|
||||||
(stack[top] == '{') ? '}' :
|
printf("Crossed bracket '%c' at position %d, expected '%c'\n", current, i, expected);
|
||||||
(stack[top] == '[') ? ']' :
|
|
||||||
(stack[top] == '(') ? ')' : '>',
|
|
||||||
current, i;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
top--;
|
top--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (top != -1) {
|
if (top != -1) {
|
||||||
char expected = expectedClosing(stack[top]);
|
printf("Missing closing brackets: ");
|
||||||
printf("Missing closing brackets: %c\n", expected);
|
while (top != -1) {
|
||||||
|
printf("%c", expectedClosing(stack[top--]));
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user