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

View File

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