I\'ve been searching how to do it in other languages and I\'ve found that I have to use the special character \\b to remove the last character. (how-do-i-erase-printed-chara
Now you could use readline library and its API to do this stuff.
readline