Update cv3/program.c

This commit is contained in:
Yurii Yakovenko 2024-10-14 20:18:38 +00:00
parent a63226d50a
commit f66c405e61

View File

@ -2,7 +2,7 @@
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #include <ctype.h>
/////////////@@@@@@@@@@@@@@ ///@
#define STACK_SIZE 500 #define STACK_SIZE 500
struct Stack struct Stack
@ -31,7 +31,7 @@ float pop_stack(struct Stack* stack)
} }
int count_stack(struct Stack* stack) int count_stack(struct Stack* stack)
{ {
return stack->size;
} }
void print_stack(struct Stack* stack) void print_stack(struct Stack* stack)
@ -62,6 +62,12 @@ int main()
float op1, op2, rez; float op1, op2, rez;
if(c=='+'||c=='-'||c=='/'||c=='*') if(c=='+'||c=='-'||c=='/'||c=='*')
{ {
if(count_stack(&mystack)<2)
{
printf("not enough operands\n");
err=3;
break;
}
op2=pop_stack(&mystack); op2=pop_stack(&mystack);
op1=pop_stack(&mystack); op1=pop_stack(&mystack);
switch(c) switch(c)
@ -97,9 +103,8 @@ int main()
print_stack(&mystack); print_stack(&mystack);
} }
} }
else { else break;
break;
}
}while(1); }while(1);
if(!err) if(!err)
printf("no input\n"); printf("no input\n");
@ -108,4 +113,3 @@ int main()