And it simply does not work...
So what does it do? Nothing? I assume you're not getting any debug output from the serial print.
One issue, at least as far as I can see from that snippet is that you assume that inpos is less than outpos. Have you ensured that it is?