int main(void) { printf("f="); formula *f_tree = input_formula(); if (f_tree) { printf("f'="); out_derivative(f_tree); printf("\n"); } else printf("Incorrect formula\n"); free_tree(f_tree); return 0; }
formula *next_formula_part() { formula *res = NULL; char c = getchar(); switch (c) { case '(': res = input_formula(); if (getchar() != ')') { free_tree(res); return NULL; } break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'x': res = (formula *)malloc(sizeof(formula)); res->smb = c; res->left = res->right = NULL; break; default: break; } return res; }
int calc(void) { char buf[1024]; double ret; init_token_type(); f_was_calc = 1; printf("> "); /* prompt */ if(input_formula(buf, sizeof(buf)) == -1) return -1; if(to_RPN(buf) == -1) return -1; ret = calc_RPN(); if(f_error) return 0; append_variable_value("prev", ret); if(variable_name[0] != '\0') { append_variable_value(variable_name, ret); } /* real number or natural number */ if(f_was_calc) print_style(ret); return 0; }