Monday 13 February 2012

Strip specified character from a string


Q: Write a function that removes all instances of a specified character from a provided string.

A: Function can do that in-place - it needs to maintain two pointers in the string - one (i) that advances and looks for character and zero termination character and another one (j) which follows the first one and points to the place in the string where the next allowed character will be copied. On the return, input string has the same or smaller size than original string.