File: example3.c

package info (click to toggle)
mmseqs2 12-113e3%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 25,760 kB
  • sloc: cpp: 67,306; ansic: 6,279; sh: 2,425; makefile: 94; perl: 32
file content (35 lines) | stat: -rw-r--r-- 722 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "tinyexpr.h"
#include <stdio.h>


/* An example of calling a C function. */
double my_sum(double a, double b) {
    printf("Called C function with %f and %f.\n", a, b);
    return a + b;
}


int main(int argc, char *argv[])
{
    te_variable vars[] = {
        {"mysum", my_sum, TE_FUNCTION2}
    };

    const char *expression = "mysum(5, 6)";
    printf("Evaluating:\n\t%s\n", expression);

    int err;
    te_expr *n = te_compile(expression, vars, 1, &err);

    if (n) {
        const double r = te_eval(n);
        printf("Result:\n\t%f\n", r);
        te_free(n);
    } else {
        /* Show the user where the error is at. */
        printf("\t%*s^\nError near here", err-1, "");
    }


    return 0;
}