From 13ee4c0bfb0fcb57a86695097a3d34285406e0ad Mon Sep 17 00:00:00 2001 From: Yurii Yakovenko Date: Fri, 25 Oct 2024 20:20:59 +0000 Subject: [PATCH] Update a1/program.c --- a1/program.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/a1/program.c b/a1/program.c index 117e2ad..af7e150 100644 --- a/a1/program.c +++ b/a1/program.c @@ -69,7 +69,7 @@ int main() if(c=='<'||c=='('||c=='{'||c=='[') { push_stack(&mystack, c); - + } if(c=='>'||c==']'||c=='}'||c==')') { @@ -77,41 +77,45 @@ int main() cs=pop_stack(&mystack); else { - printf("\nUnexpected closing bracket %c in %d\n", c,i); + printf("\nUnexpected closing bracket %c in %d\n", c,i); is_ok=false; break; } if(c=='>' && cs!='<') { - printf("\nCrossed bracket %c in %d, expected %c", c, i, para(c)); + printf("\nCrossed bracket %c in %d, expected %c", c, i, para(cs)); + is_ok=false; + break; + } + if(c==']' && cs!='[') + { + printf("\nCrossed bracket %c in %d, expected %c", c, i, para(cs)); is_ok=false; break; } if(c==')' && cs!='(') { - printf("\nCrossed bracket %c in %d, expected %c", c, i, para(c)); - is_ok=false; - break; - } - if(c==')' && cs!='(') - { - printf("\nCrossed bracket %c in %d, expected %c", c, i, para(c)); + printf("\nCrossed bracket %c in %d, expected %c", c, i, para(cs)); is_ok=false; break; } if(c=='}' && cs!='{') { - printf("\nCrossed bracket %c in %d, expected %c", c, i, para(c)); + printf("\nCrossed bracket %c in %d, expected %c", c, i, para(cs)); is_ok=false; break; } } i++; } - - if(is_ok) - printf("\nAll brackets OK\n"); - + + if(count_stack(&mystack)>0) + { + cs=pop_stack(&mystack); + printf("\nMissing closing brackets: %c\n", para(cs)); + } + else if(is_ok) + printf("\nAll bracket OK");