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

@ -29,15 +29,18 @@ int main(){
memset(&myStack,0,sizeof(struct stack));
while(1){
ptr = fgets(char_value, STACK_SIZE-1, stdin);
if(ptr != NULL ){
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 {
push_stack(&myStack, float_value);
} 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{
}
}else {
//push_stack(&myStack, float_value);
//print_stack(&myStack);
//printf("\n");
puts("no input");
break;
}