eval_form().
By SalimMeghani
- 382 reads
double eval_form(int *error, char *form)
{
double answer =0,
no1=0,
no2=0;
int loop=0,
nega=0,
opvalid=0,
place=0;
c=0; s=0;
while(form[c]!='%')
{
int fm=0;
if (form[c]=='P') c++;
if (form[c]==',') c++;
while(form[c]==' ') { c++; }
//
if (form[c]=='%') break;
while((form[c]>='0') && (form[c]<='9') || form[c]==' ' || form[c]=='M' || form[c]=='.')
{
while (form[c]=='M')
{
if (fm==1) fm=0; else fm=1;
c++;
if (form[c]==',') c++;
}
str=0;
clr_str(star);
notrue=0;
while ((form[c]>='0') && (form[c]<='9') || (form[c]=='.'))
{
{
star[str]=form[c];
str++;
c++;
notrue=1;
}
}
if ((form[c+1] == 'E') || (form[c+1] == 'e')) c++;
if ((form[c]=='E') || (form[c]=='e'))
{
star[str]=form[c];
c++;
str++;
star[str]=form[c];
c++;
str++;
while ((form[c]>='0') && (form[c]<='9'))
{
{
star[str]=form[c];
str++;
c++;
notrue=1;
}
}
}
if (notrue==1)
{
if (fm!=1)
{
pushstk(atof(star));
}
else
{
pushstk(-atof(star));
fm=0;
}
notrue=0;
}
c++;
}
while(form[c]==0) {c++;}
if (form[c]=='%') break;
right1=popstk();
left1=popstk();
if (form[c]=='+')
answer=left1+right1;
else
if (form[c]=='-')
answer=left1-right1;
else
if (form[c]=='*')
answer=left1*right1;
else
if (form[c]=='/')
if (right1==0) {
*error=1;
answer=0;}
else
answer=left1/right1;
pushstk(answer);
c++;
}
//
answer=popstk();
if (answer==-0) answer=0;
return(answer);
}
//
void clear_vars(void)
{
clr_str(calif);
clr_str(texas);
//clr_str(form3);
//clr_str(newyk);
clr_str(star);
switc=NULL; // This is the switch
previous=NULL;
bop=NULL;
frop=NULL;
right1=NULL;
left1=NULL;
no=0;
rgt=NULL;
lft=NULL;
blop=NULL;
check=NULL;
op=NULL;
rop=NULL;
lop=NULL;
x=0;
s=0;
c=0;
n=0;
g=0;
notrue=0;
str=0;
start=0;
end=0;
bracket=0;
length=0;
sol=0;
}
- Log in to post comments