Category : C Source Code
Archive   : ASOLVER.ZIP
Filename : EX2.C

 
Output of file : EX2.C contained in archive : ASOLVER.ZIP
/****************************************/
/* */
/* EXAMPLE #2 */
/* */
/* Algebraic Expression Solver */
/* */
/* Copyright 1989, Ryan Software */
/* */
/****************************************/

#include
#include
#include
#include
#include
#include
#include "asolver.h"

FILE *handle, *fopen();

/****************/
/* */
/* main program */
/* */
/****************/

main(argc,argv)
int argc;
char *argv[];
{
char input_file[16];
char *p;
char *prog;
int mode,err;
double answer;

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)
{
err = a_solver(mode,prog,&answer);
if(err == A_S_NOER)
{
printf("Answer = %lf\n",answer);
}
else
{
if(err != A_S_BLNK) 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);

}



  3 Responses to “Category : C Source Code
Archive   : ASOLVER.ZIP
Filename : EX2.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. 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/