From 9fc60b89cffc9f6fad317e95819648af744a12ea Mon Sep 17 00:00:00 2001 From: Yevhen Kozirovskyi Date: Thu, 31 Oct 2024 23:35:07 +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 | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/a1/program.c b/a1/program.c index 73f2b85..7dc30f0 100644 --- a/a1/program.c +++ b/a1/program.c @@ -11,11 +11,14 @@ typedef struct { int main() { char line[MAX_LEN + 1]; StackItem stack[MAX_LEN]; - int top = -1; + 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; }