0

I need to be able to get rid of spaces in a string. All strings are representations of functions:

3 * x ( 1 ) + 1 * x ( 3 ) + 6 * x ( 2 ) – 10 * X ( 0 )

and i have to build a trim function that turns the above into:

3*x(1)+1*x(3)+6*x(2)–10*X(0)

i have tried the below but it just copies the string.

```
int main (void)
{
string function = "3 * x ( 1 ) + 1 * x ( 3 ) + 6 * x ( 2 ) – 10 * X ( 0 )";
cout << function << endl;
trim(function);
cout << function;
system("pause");
}
void trim(string& s)
{
int length = s.length();
string copy;
copy = s;
int k = 0;
for (int i = 0; i<length; i++)
{
//position of s
if (copy[i] = ' ')
{
continue;
}
else
{
s[k] = copy[i];
k++;
}
}
}
```

Any help would be appreciated!