Update cv3/program.c

This commit is contained in:
Marat Izmailov 2024-10-17 11:30:23 +00:00
parent cee902690b
commit 204652d772

View File

@ -30,17 +30,14 @@ int main() {
input[strcspn(input, "\n")] = 0; input[strcspn(input, "\n")] = 0;
if (strlen(input) == 0) { if (strlen(input) == 0) {
printf("no input\n"); printf("no input\n");
break; break;
} }
if (is_number(input)) { if (is_number(input)) {
float value = atof(input); float value = atof(input);
push_stack(&mystack, value); push_stack(&mystack, value);
} else if (strlen(input) == 1 && strchr("+-*/", input[0])) { } else if (strlen(input) == 1 && strchr("+-*/", input[0])) {
if (mystack.size < 2) { if (mystack.size < 2) {
fprintf(stderr, "Error: Not enough values in stack.\n"); fprintf(stderr, "Error: Not enough values in stack.\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -76,13 +73,13 @@ int main() {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
print_stack(&mystack); print_stack(&mystack);
} }
return 0; return 0;
} }
void push_stack(struct stack* stack, float value) { void push_stack(struct stack* stack, float value) {
assert(stack->size < STACK_SIZE); assert(stack->size < STACK_SIZE);
stack->values[stack->size] = value; stack->values[stack->size] = value;