From f66c405e61da94aa95796b1c489f4db6564bf7fa Mon Sep 17 00:00:00 2001 From: Yurii Yakovenko Date: Mon, 14 Oct 2024 20:18:38 +0000 Subject: [PATCH] Update cv3/program.c --- cv3/program.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/cv3/program.c b/cv3/program.c index 7b9a5ac..30ad455 100644 --- a/cv3/program.c +++ b/cv3/program.c @@ -2,7 +2,7 @@ #include #include #include - /////////////@@@@@@@@@@@@@@ +///@ #define STACK_SIZE 500 struct Stack @@ -31,7 +31,7 @@ float pop_stack(struct Stack* stack) } int count_stack(struct Stack* stack) { - + return stack->size; } void print_stack(struct Stack* stack) @@ -62,6 +62,12 @@ int main() float op1, op2, rez; if(c=='+'||c=='-'||c=='/'||c=='*') { + if(count_stack(&mystack)<2) + { + printf("not enough operands\n"); + err=3; + break; + } op2=pop_stack(&mystack); op1=pop_stack(&mystack); switch(c) @@ -97,9 +103,8 @@ int main() print_stack(&mystack); } } - else { - break; - } + else break; + }while(1); if(!err) printf("no input\n"); @@ -108,4 +113,3 @@ int main() -