hey guys, i wrote another function, which i think makes more sense ,
again the function would calculate each expression's multipicant and power in each call, and this is how it works
suppose we have a formula like : 4X^2 + 3X^5 - 65X^-5
so there are 3 expressions in the formula. because i declared 'i' as static, in each call, it would resume the process and continue from where it was intruptted and thus , fetching the next expression and calculating the stuff.
however , its not working!and i know which part is malfunctioning but have no idea why it is doing so!
can you tell me why?
by the way i used those printf()s to trace the program and see whats going on down there! so that i can be able to figure out what the problem is :
so far i undrstood that the problem is caused by the inner loop, which calculates Power!, i dont know why it keeps going and going! instead of stopping when encountered to either '-' or '+' ( meaning a new operator and thus meaning the end of this current expression)
it seems it ignores the sign and keeps going! dont know how to get it out of that loop! it doesnt even check the if statement i placed inside the loop!
guilty loop:
Code:
if ( string[i] =='^')
{
i++;
do {
if ( k == 0)
printf("\ninside 1...inside Power do while string = %c i = %d k = %d\n",string[i],i,k);
Power_char[k] = string[i];
i++;
k++;
printf("\ninside 2...inside Power do while string = %c i = %d k = %d\n",string[i],i,k);
if ((string[i] == '-') || (string[i] == '+') )
{
printf("\n in if(Power) string[%d] = %c",i,string[i]);
// i++;
break;
}
}while ((string[i] != '-') || (string[i] != '+') );
if ((string[i] == '-') || (string[i] == '+') )
{
printf("\n in if(Power) string[%d] = %c",i,string[i]);
//i++;
break;
}
}
the whole function:
Code:
void return_expo(char string[],int size,double *Multipicant,double *Power)
{
char * expoo =" ";
char Multipicant_char[5];
char Power_char[5];
static int i = 0;
int j = 0;
int count = 0;
int counter = 0;
int k =0;
do
{
printf("\ninside firs do..while..\n");
while (string[i]!='x' || string[i]!='X')
{
//printf("\ninside first do..while..inside Multipicant while string = %c i = %d j = %d\n",string[i],i,j);
Multipicant_char[j] = string[i];
i++;
j++;
//printf("\ninside first do..while..inside Multipicant while string = %c i = %d j = %d\n",string[i],i,j);
if (string[i] =='x' || string[i] =='X')
{
i++;
break;
}
}
printf("\ninside first do..while..after Multipicant while string = %c i = %d j = %d\n",string[i],i,j);
if ( string[i] =='^')
{
i++;
do {
if ( k == 0)
printf("\ninside 1...inside Power do while string = %c i = %d k = %d\n",string[i],i,k);
Power_char[k] = string[i];
i++;
k++;
printf("\ninside 2...inside Power do while string = %c i = %d k = %d\n",string[i],i,k);
if ((string[i] == '-') || (string[i] == '+') )
{
printf("\n in if(Power) string[%d] = %c",i,string[i]);
// i++;
break;
}
}while ((string[i] != '-') || (string[i] != '+') );
if ((string[i] == '-') || (string[i] == '+') )
{
printf("\n in if(Power) string[%d] = %c",i,string[i]);
// i++;
break;
}
}
printf("\n what? %c ",string[i]);
}while ( (string[i] !='-') ||(string[i] !='+' ) );
i++;
printf("\nOutside the loop i = %d j = %d\n",i,j);
*Multipicant = atof(Multipicant_char);
*Power = atof(Power_char);
return ;
}
tanx