Обновить a1/program.c

This commit is contained in:
Yevhen Kozirovskyi 2024-10-31 23:35:07 +00:00
parent 5aab1928a4
commit 9fc60b89cf

View File

@ -13,9 +13,12 @@ int main() {
StackItem stack[MAX_LEN];
int top = -1;
printf("Enter the code: ");
fgets(line, sizeof(line), stdin);
printf("Read: %s", line);
// Odstránime nový riadok na konci vstupu, ak existuje
line[strcspn(line, "\n")] = 0;
printf("Read: %s\n", line);
for (int i = 0; line[i] != '\0'; i++) {
char ch = line[i];
@ -25,10 +28,9 @@ int main() {
stack[++top].bracket = ch;
stack[top].position = i;
}
}
else if (ch == ')' || ch == '}' || ch == ']' || ch == '>') {
} else if (ch == ')' || ch == '}' || ch == ']' || ch == '>') {
if (top == -1) {
printf("Unexpected closing bracket %c in %d\n", ch, i);
return 0;
}