home *** CD-ROM | disk | FTP | other *** search
- /*********************************************************
- *
- * example program of useing defunc (Ke Jin 1993)
- *
- *********************************************************/
- #include <stdio.h>
- #include <math.h>
- #include <defunc.h>
-
- int main()
- {
- double (*fp)();
- char expr[128];
- double x;
-
- matha2z(); /* portable functions in math lib into token table */
-
- printf("\n\tEnter a expression please.\n");
-
- for(;;)
- {
- printf("\n\tinput > ");
- fgets(expr, 127, stdin);
- expr[strlen(expr)-1]='\0'; /* strip off the '\n' on end */
-
- if(strncmp(expr, "quit", 4)==0||
- strncmp(expr, "exit", 4)==0)
- {
- printf("\n\t\t--------- Bye! ---------\n\n");
- return 0;
- }
-
- fp = dfopen(expr);
- if(fp==0) {
- if(exparserror!=0)
- printf("\t\t%s\n", exparserror);
- else
- printf("\t\tempty expression body\n");
- exparserror = 0;
-
- printf("\n\t\tcurrent arguments are %s, %s\n",
- getarguname(1), getarguname(2));
-
- continue;
- }
-
- printf("\t\t%s\t\t%s\n", getarguname(1), expr);
- for(x=0.0;x<1.0;x=x+0.1)
- {
- printf("\t\t%f\t%f\n", x, fp(x,0));
- }
- printf("\n\t\tcurrent arguments are %s, %s\n",
- getarguname(1), getarguname(2));
-
- dfclose(fp);
- }
- }
-