From 8ec9471e7314a38dd3826eae3ce03b72369c79c6 Mon Sep 17 00:00:00 2001 From: Yevhen Kozirovskyi Date: Thu, 31 Oct 2024 23:37:39 +0000 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20a1/program.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- a1/program.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/a1/program.c b/a1/program.c index e24997e..c822094 100644 --- a/a1/program.c +++ b/a1/program.c @@ -13,9 +13,10 @@ int main() { StackItem stack[MAX_LEN]; int top = -1; + fgets(line, sizeof(line), stdin); - // Odstránime nový riadok na konci vstupu, ak existuje + // Odstránenie nového riadku na konci vstupu, ak existuje line[strcspn(line, "\n")] = 0; printf("Read: %s\n", line); @@ -54,8 +55,20 @@ int main() { } } + // Ak sú v zásobníku neuzavreté otváracie zátvorky if (top != -1) { - printf("Unmatched opening bracket %c at position %d\n", stack[top].bracket, stack[top].position); + printf("Missing closing brackets: "); + while (top != -1) { + char expected; + switch (stack[top--].bracket) { + case '(': expected = ')'; break; + case '{': expected = '}'; break; + case '[': expected = ']'; break; + case '<': expected = '>'; break; + } + printf("%c", expected); + } + printf("\n"); } else { printf("All brackets OK\n"); }