There are several ways to do it. One way is to parse the string one character at a time. Something like this (Note: This was not compiled or tested, so use it at your own risk).
This does not solve your entire problem -- it just gets the numeric data. Your program will have to do something else to extract the math operator '-', '+', '*' and '/'. If you understand the code I am posting here then extracting the math symbol should not be a problem for you.
char* GetInt(char* str, int& n)
{
n = 0;
// skip over all non-digit characters
while(*str && !isdigit(*str) )
++str;
// convert all digits to an integer
while( *str && isdigit(*str) )
{
n = (n * 10) + *str - '0';
++str;
}
return str;
}
int main()
{
char* str = "q23 - q3 (or q23-q3)";
int x,y,z;
str = GetInt(str,x);
str = GetInt(str,y);
str = GetInt(str,z);
} Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343