0

Given the input ~Zw~~"iE^L I should get !w~"iE^L instead I am getting Zw~"iE^L

So it catch the ~~ just fine and replace it with ~ but I want to replace ~Z with !

Any ideas?

  for (j = 0; j < dataCharCount; j++, k++)
  {
    if (inputData[j] == '~' && inputData[j + 1] == '~')
    {
      filteredInputData[k] = '~';
      j++;
    }
    else if (inputData[j] == '~' && inputData[j + 1] == 'Z')
    {
      filteredInputData[k] = '!';
      j++;

    }
    filteredInputData[k] = inputData[j];
  }
1
  • you could have found the problem by using your debugger... Commented Mar 20, 2011 at 17:59

3 Answers 3

3
} else {
    filteredInputData[k] = inputData[j];
}

Without the else you're overwriting filteredInputData[k] after the if statements.

Sign up to request clarification or add additional context in comments.

Comments

0

there is an else missing before the last ine of the function. you surely do not want to copy the input to the output (filteredInputData[k] = inputData[j];) after having performed the replacement.

Comments

0

The last statement in your loop overwrites the ~ or ! you wrote via your if statment body. The reason it looks like it works for the ~~ is that it's overwriting the ~ with another ~. In the ~Z case, you're overwriting your ! with the Z. Step through your code with a debugger - you'll see what's happening immediately.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.