1 #include "tinyexpr.h"
2 #include <stdio.h>
3
4
5 /* An example of calling a C function. */
my_sum(double a,double b)6 double my_sum(double a, double b) {
7 printf("Called C function with %f and %f.\n", a, b);
8 return a + b;
9 }
10
11
main(int argc,char * argv[])12 int main(int argc, char *argv[])
13 {
14 te_variable vars[] = {
15 {"mysum", my_sum, TE_FUNCTION2}
16 };
17
18 const char *expression = "mysum(5, 6)";
19 printf("Evaluating:\n\t%s\n", expression);
20
21 int err;
22 te_expr *n = te_compile(expression, vars, 1, &err);
23
24 if (n) {
25 const double r = te_eval(n);
26 printf("Result:\n\t%f\n", r);
27 te_free(n);
28 } else {
29 /* Show the user where the error is at. */
30 printf("\t%*s^\nError near here", err-1, "");
31 }
32
33
34 return 0;
35 }
36