From c5605e5b2c2f3f63f07c05a5c3972e695dc2d921 Mon Sep 17 00:00:00 2001 From: Yurii Yakovenko Date: Mon, 14 Oct 2024 19:46:13 +0000 Subject: [PATCH] Update cv3/program.c --- cv3/program.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/cv3/program.c b/cv3/program.c index 578b096..9b33161 100644 --- a/cv3/program.c +++ b/cv3/program.c @@ -1,7 +1,7 @@ #include #include #include - +////@@@@ #define STACK_SIZE 500 struct Stack @@ -17,13 +17,13 @@ int count_stack(struct Stack* stack); void push_stack(struct Stack* stack, float value) { - assert(stack->size < STACK_SIZE); + assert(stack->size < STACK_SIZE); // Program spadne, ak zapisuje mimo stack->values[stack->size] = value; stack->size += 1; } float pop_stack(struct Stack* stack) { - assert(stack->size > 0); + assert(stack->size > 0); // Program spadne, ak číta mimo float value = stack->values[stack->size-1]; stack->size -= 1; return value; @@ -37,8 +37,9 @@ void print_stack(struct Stack* stack) { for (int i=0; isize; i++) { - printf("%f/", stack->values[i]); + printf("%.2f ", stack->values[i]); } + printf("\n"); } @@ -54,9 +55,10 @@ int main() do { char* p=fgets(buf, 299, stdin); - + //printf("{%s}",buf); if(!p) - { + { + //printf("=="); break; } else @@ -73,13 +75,15 @@ int main() case '-': rez=op1-op2; break; case '/': rez=op1/op2; break; case '*': rez=op1*op2; break; - } - push_stack(&mystack, rez); - printf(" %.2f\n", rez); - + } //p } else - push_stack(&mystack, atof(buf)); + { + rez=atof(buf); + } + push_stack(&mystack, rez); + //printf(" %.2f\n", rez); + print_stack(&mystack); } }while(1);