From 6d18b78144950ec9298efd4079494ab8e2f343ff Mon Sep 17 00:00:00 2001 From: Deinerovych Date: Wed, 16 Oct 2024 10:12:58 +0200 Subject: [PATCH] 5 --- cv3/program.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/cv3/program.c b/cv3/program.c index 182b8bf..98f48e3 100644 --- a/cv3/program.c +++ b/cv3/program.c @@ -60,6 +60,7 @@ int main() { char arr[50]; char *pend; stack_top = -1; + bool first_output = true; while (fgets(arr, 50, stdin)) { if (arr[0] == '\n' || arr[0] == EOF) { @@ -69,11 +70,19 @@ int main() { if (is_number(arr)) { float number = strtof(arr, &pend); push(number); - printf("%.2f\n", number); + if (!first_output) { + printf(" "); + } + printf("%.2f", number); + first_output = false; } else if (is_operation(arr)) { if (stack_top < 1) { - printf("no input\n"); + if (!first_output) { + printf(" "); + } + printf("no input"); + first_output = false; continue; } @@ -82,20 +91,35 @@ int main() { char operation = arr[0]; float result = calculator(n1, n2, operation); push(result); - printf("%.2f\n", result); + if (!first_output) { + printf(" "); + } + printf("%.2f", result); + first_output = false; } else { - printf("no input\n"); + if (!first_output) { + printf(" "); + } + printf("no input"); + first_output = false; continue; } } if (stack_top == 0) { - printf("%.2f\n", pop()); + if (!first_output) { + printf(" "); + } + printf("%.2f", pop()); } else { - printf("no input\n"); + if (!first_output) { + printf(" "); + } + printf("no input"); } + printf("\n"); return 0; }