You can do a char by char analysis of the string looking char one at a time using (usually somewhat convoluted) logic to determine what is legal to follow any given char, particularly if you want to handle something like "6 - (- 54 - (-61))". That space between the - and 54 is something you and I can handle okay, but it is a bit a futsy business when you try to write code to handle it.
int number = 0;
char digitC = 0;
double grade = 0;
bool numberIsNegative = false;
//point is the index (where we are at string)
int tempPoint = point;
//lastPoint string lenght
while( point != (lastPoint + 1) && ( isdigit( digitC = problemString[point] ) || problemString[point] == '-' || problemString[point] == '+' ))
//looking the number is negative or positive
if(problemString[point] == '-')
numberIsNegative = true;
else if (problemString[point] == '+')
tempPoint = point;
//looking grade of number example if the number 121 it will be 3
//if it's 1041 it will be four
while( tempPoint != (lastPoint + 1) && isdigit( digitC = problemString[tempPoint] ) )
//taking the number from string
while( point != (lastPoint + 1) && isdigit( digitC = problemString[point] ) )
digit = atoi(&digitC);
number = number + digit* pow(BASE,grade-1);//BASE = 10
if (grade == 0)
number = -number;
but that had been easy part of my program. it will be a calculator and you can use parenthesises.
it can solve
result = -618
but it gives the wrong value with that simple question :)
result = 1 :) i didn't think the precedence
it must be 16
i will handle this tomorrow
thx for all replies.
I think you'll wind up with something weird, but what happens if you eliminate (space) as a delimiter? Also, this code looks more like C than C++, you might consider trying over there as well.
i wrote the code in C. . Because I was just trying atof and other functions.
in fact i edited some code
For Each ctrl As Control In Me.Controls("pnlMainPanel").Controls
If ctrl.GetType Is GetType(System.Windows.Forms.Panel) Then
For Each subCtrl As Control In ctrl.Controls
If subCtrl.GetType Is GetType(System.Windows.Forms.TextBox) Then
If subCtrl.GetType Is ...