bad input

This commit is contained in:
Valér Jakubčo 2021-10-21 23:20:42 +02:00
parent deea72d872
commit 1cb9718f53

View File

@ -30,14 +30,17 @@ int main(){
while(1){
ptr = fgets(char_value, STACK_SIZE-1, stdin);
if(ptr != NULL){
if(char_value[0] == '\n'){
puts("no input");
break;
}
if(char_value[0] == '0'){
push_stack(&myStack,0);
print_stack(&myStack);
printf("\n");
continue;
}
float_value = strtof(char_value, NULL);
if(float_value == 0){
if(char_value[0] == '+'){
float a = pop_stack(&myStack);
float b = pop_stack(&myStack);
@ -45,43 +48,47 @@ int main(){
push_stack(&myStack, c);
print_stack(&myStack);
printf("\n");
}
if(char_value[0] == '-'){
}else if(char_value[0] == '-'){
float a = pop_stack(&myStack);
float b = pop_stack(&myStack);
float c = b-a;
push_stack(&myStack, c);
print_stack(&myStack);
printf("\n");
}
if(char_value[0] == '*'){
}else if(char_value[0] == '*'){
float a = pop_stack(&myStack);
float b = pop_stack(&myStack);
float c = a*b;
push_stack(&myStack, c);
print_stack(&myStack);
printf("\n");
}
if(char_value[0] == '/'){
} else if(char_value[0] == '/'){
float a = pop_stack(&myStack);
if(a == 0){
printf("division by zero\n");
break;
}
}else{
float b = pop_stack(&myStack);
float c = b/a;
push_stack(&myStack, c);
print_stack(&myStack);
printf("\n");
}
} else {
float_value = strtof(char_value, NULL);
if(float_value == 0){
puts("bad input");
break;
} else {
push_stack(&myStack,float_value);
print_stack(&myStack);
printf("\n");
continue;
}
}
}else {
//push_stack(&myStack, float_value);
//print_stack(&myStack);
//printf("\n");
puts("no input");
break;
}