Category : C Source Code
Archive   : ASOLVER.ZIP
Filename : EX3.C
Output of file : EX3.C contained in archive : ASOLVER.ZIP
/* */
/* EXAMPLE #3 */
/* */
/* Algebraic Expression Solver */
/* */
/* Copyright 1989, Ryan Software */
/* */
/****************************************/
#include
#include
#include
#include
#include
#include
#include "asolver.h"
FILE *handle, *output, *fopen();
/****************/
/* */
/* main program */
/* */
/****************/
main(argc,argv)
int argc;
char *argv[];
{
char *parse_line();
char input_file[16];
char *p;
char *prog,*equation;
int i,mode,err;
double answer;
bool DISPLAY = FALSE;
mode = 1;
p=malloc(100);
if(!p)
{
printf("Insufficent memory\n");
exit(0);
}
if(argc>1)
{
prog = p;
strcpy(input_file,argv[1]);
handle = fopen(input_file,"r");
while(fget_line(handle,prog) != EOF)
{
/* prog = strlwr(strdup(prog)); */
if(strnicmp(prog,"rem:",4) == 0)
{
/* it is a remark so do nothing */
}
else if(strnicmp(prog,"comment:",8) == 0)
{
/* it is a comment print it */
printf("%s\n",parse_line(prog));
}
else if(strnicmp(prog,"save:",5) == 0)
{
output = fopen("SOLVE.ANS","w");
fprintf(output,"%lf",answer);
fclose(output);
}
else if(strnicmp(prog,"store:",6) == 0)
{
strcpy(equation,prog);
}
else if(strnicmp(prog,"solve:",6) == 0)
{
prog = parse_line(equation);
err = a_solver(mode,prog,&answer);
if(err==0)
{
printf("%lf\n",answer);
DISPLAY = FALSE;
}
if(err != A_S_BLNK && err != A_S_NOER)
{
errmsg(err);
}
}
else if(strnicmp(prog,"answer:",7) == 0)
{
printf("%s ",parse_line(prog));
DISPLAY = TRUE;
}
else
{
err = a_solver(mode,prog,&answer);
if(DISPLAY && err == A_S_NOER)
{
printf("%lf\n",answer);
DISPLAY = FALSE;
}
if(err != A_S_BLNK && err != A_S_NOER)
{
errmsg(err);
}
}
prog = p;
}
}
exit(0);
}
/******************/
/* error messages */
/******************/
errmsg(code)
int code;
{
if(code== A_S_SYNT) printf("Syntax error\n");
if(code== A_S_PARG) printf("Unbalanced parentheses\n");
if(code== A_S_NEXP) printf("No expression present\n");
if(code== A_S_ILLC) printf("Illegal character in expression\n");
if(code== A_S_BLNK) printf("Blank line\n");
if(code== A_S_DIV0) printf("Division by zero\n");
if(code== A_S_LOGA) printf("Logarithm of a negative number\n");
if(code== A_S_FACT) printf("Factorial of a negative number\n");
if(code== A_S_SQRT) printf("Square root of a negative number\n");
exit(-1);
}
/*************************************/
/* parse the line to get the options */
/*************************************/
char *parse_line(prog)
char *prog;
{
char *line;
while(*prog != ':') *prog++;
*prog++;
return(prog);
}
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/