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