This commit is contained in:
Bohdan Kapliuk 2024-10-27 22:53:45 +02:00
parent 7d01f2a2cf
commit ae36a3dfe9

View File

@ -9,7 +9,8 @@ int main() {
char *brackets1 = "}])>";
char stack[LINESIZE];
int position[LINESIZE];
int x = 0;
int x = 0;
char expected = '\0';
fgets(vstup, LINESIZE, stdin);
printf("Read: %s", vstup);
for (int j = 0; j < strlen(vstup); j++) {
@ -20,7 +21,6 @@ int main() {
x++;
break;
} else if (vstup[j] == brackets1[i]) {
char expected = '\0';
if (stack[x-1] == '{') expected = '}';
else if (stack[x-1] == '[') expected = ']';
else if (stack[x-1] == '(') expected = ')';
@ -43,7 +43,7 @@ int main() {
}
}
if (x > 0) {
printf("Missing closing brackets: %c\n", stack[x-1]);
printf("Missing closing brackets: %c\n", expected);
} else {
printf("All brackets OK\n");
}