From 23b008887de0cca9f5b274eb7c6475baecfc0df9 Mon Sep 17 00:00:00 2001 From: Yurii Chechur Date: Sun, 13 Oct 2024 15:05:13 +0000 Subject: [PATCH] Update cv3/program.c --- cv3/program.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/cv3/program.c b/cv3/program.c index 35c47cc..1092d4c 100644 --- a/cv3/program.c +++ b/cv3/program.c @@ -34,10 +34,12 @@ float pop_stack(struct stack *s) { } void print_stack(struct stack *s) { - for (int i = 0; i < s->size; i++) { - printf("%.2f ", s->values[i]); + if (s->size > 0) { + for (int i = 0; i < s->size; i++) { + printf("%.2f ", s->values[i]); + } + printf("\n"); } - printf("\n"); } int read(struct stack *s) { @@ -76,7 +78,7 @@ int read(struct stack *s) { // Check for sufficient values in the stack if (s->size < 2) { printf("no input\n"); - exit(1); // Exit if not enough values + return 1; // Don't exit; continue to next iteration } float b = pop_stack(s); // Pop the last two values @@ -96,8 +98,9 @@ int read(struct stack *s) { break; } push_stack(s, result); // Push the result back onto the stack - // Print the result print_stack(s); // Print the stack after operation + printf("no input\n"); // Print the "no input" message + exit(0); // Exit the program after the operation break; } default: