From 32e9d7d67192ab7f059414ac309c0ac2e248bcae Mon Sep 17 00:00:00 2001 From: Anton Dolozin Date: Mon, 13 Oct 2025 17:38:09 +0200 Subject: [PATCH] Trying --- a1/program.c | 51 ++++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/a1/program.c b/a1/program.c index 00043a6..d96b476 100644 --- a/a1/program.c +++ b/a1/program.c @@ -74,25 +74,7 @@ void read_input(LinkedNode** head){ { if(buff[i] == '[' || buff[i] == '<' || buff[i] == '{' || buff[i] == '('){ push(head, buff[i]);} - if(buff[i] == '[' || buff[i] == '<' || buff[i] == '{' || buff[i] == '(' && *head != NULL){ - if(buff[i] == '['){ - printf("Read: %sMissing closing brackets: ]\n", buff); - return; - } - if(buff[i] == '{'){ - printf("Read: %sMissing closing brackets: }\n", buff); - return; - } - if(buff[i] == '<'){ - printf("Read: %sMissing closing brackets: >\n", buff); - return; - } - if(buff[i] == '('){ - printf("Read: %sMissing closing brackets: )\n", buff); - return; - } - - } + if(buff[i] == '>' || buff[i] == '}' || buff[i] == ']' || buff[i] == ')'){ if(*head == NULL){ printf("Read: %sUnexpected closing bracket %c in %d\n", buff, buff[i], i); @@ -100,10 +82,7 @@ void read_input(LinkedNode** head){ } char popped = pop(head); if (!compare(popped, buff[i])) - { if(popped == '[' && isalpha(buff[i])){ - printf("Read: %sMissing brackets: ]", buff); - return; - } + { if (popped == '[' && buff[i] == '>') { printf("Read: %s\n", buff); @@ -213,6 +192,32 @@ void read_input(LinkedNode** head){ } +if(*head != NULL){ + LinkedNode* ptr = *head; + while(ptr){ + if(ptr->data == '['){ + printf("Read: %sMissing closing brackets: ]\n", buff); + return; + + } + if(ptr->data == '('){ + printf("Read: %sMissing closing brackets: )\n", buff); + return; + + } + if(ptr->data == '{'){ + printf("Read: %sMissing closing brackets: }\n", buff); + return; + + + } + if(ptr->data == '<'){ + printf("Read: %sMissing closing brackets: >\n", buff); + return; + } + ptr = ptr->next; + } + } printf("Read: %sAll brackets OK\n", buff); }