CosmoGreco
Programmer
Hello Dear members of Tek-Tips.
It's not long ago since I start devoting my efforts to program application using C/C++. So I am not very familiar with all its capabilities yet.
I need to convert an entire arithmetic string expression to a result integer so C++ will calculate the expression for me without the need to develop a parser to track every single arithmetic operation.
In FoxPro for example, once I have a string with an arithmetic expression, I just do as in the following example and the result will be the final calculated expression number I want:
sVar = "10 * (10 - 5)"
iVar = &sVar
The contents of iVar after the above operation will be 50.
How do I do the same with C++?
The function atoi() will stop scanning the string right after it sees a non digit character so the example above will give me this result:
char szVar[]="10 * (10-5)";
int iVar = atoi(szVar);
The contents of iVar after the above operation will be 10 only.
Appreciate any ideas.
Regards,
Cosmo
It's not long ago since I start devoting my efforts to program application using C/C++. So I am not very familiar with all its capabilities yet.
I need to convert an entire arithmetic string expression to a result integer so C++ will calculate the expression for me without the need to develop a parser to track every single arithmetic operation.
In FoxPro for example, once I have a string with an arithmetic expression, I just do as in the following example and the result will be the final calculated expression number I want:
sVar = "10 * (10 - 5)"
iVar = &sVar
The contents of iVar after the above operation will be 50.
How do I do the same with C++?
The function atoi() will stop scanning the string right after it sees a non digit character so the example above will give me this result:
char szVar[]="10 * (10-5)";
int iVar = atoi(szVar);
The contents of iVar after the above operation will be 10 only.
Appreciate any ideas.
Regards,
Cosmo