Update a1/program.c

This commit is contained in:
Yurii Yakovenko 2024-10-25 20:36:23 +00:00
parent 0f87961d3c
commit ff87c1ef40

View File

@ -57,7 +57,7 @@ int main()
mystack.size=0;
char str[128];
fgets(str,100,stdin);
if(str[strlen(str)-1]=='\n') { str[strlen(str)-1]='\0';}
printf("Read: %s", str);
@ -65,13 +65,13 @@ int main()
int i=0;
char c, cs;
bool is_ok=true;
while(str[i]!='\0' && str[i]!='\n' && is_ok)
while(str[i]!='\0' && is_ok)
{
c=str[i];
if(c=='<'||c=='('||c=='{'||c=='[')
{
push_stack(&mystack, c);
//print_stack(&mystack);
}
if(c=='>'||c==']'||c=='}'||c==')')
{
@ -110,11 +110,16 @@ int main()
}
i++;
}
if(count_stack(&mystack)>0)
{
cs=pop_stack(&mystack);
printf("\nMissing closing brackets: %c\n", para(cs));
printf("\nMissing closing brackets: ");
do
{
cs=pop_stack(&mystack);
printf("%c", para(cs));
}while(count_stack(&mystack)>0);
printf("\n");
}
else if(is_ok)
printf("\nAll brackets OK\n");