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; }