You need to think about what you are doing a bit better:
while (i != eq.length())
{
i++;
if (isspace(eq[i]))
{continue;}
else
eq[j] = eq[i];
j++;
}
Firstly, you don't need the else: if the condition evaluates to true, then it executes the
continue
so the else isn't needed. Secondly, even if you did carray on after the if, the indentation implies that the
else
code would be both the
eq[j] = eq[i];
and the
j++;
lines - this is not the case. Thirdly, be consistent: always indent code to the proper level, it makes it easier to read:
if (isspace(eq[i]))
{continue;}
Not particularly readable, is it? :laugh:
Particularly when you are starting, always use {...} for condition execution blocks: even when they are a single statemnet - it makes it obvious and can prevent problems later, when you add code that should be executed as part of the condition.
while (i != eq.length())
{
i++;
if (isspace(eq[i]))
{
continue;
}
else
{
eq[j] = eq[i];
j++;
}
}
I would actually re-write this a lot more simply:
while (i != eq.length())
{
i++;
if (!isSpace(eq[i]))
{
eq[j] = eq[i];
j++;
}
}
Note that I changed the name of your function to match with the others!
I know this doesn't solve your problem, but try reflecting this though your code - it will make it more readable, which can only help!