c++ - Backspace character not working when printing to a file -
i have simple c program-
main() { printf("foo\b"); }
it prints fo
on terminal (as expected).
but when call program redirecting i/o-
./a.out >outfile
the outfile
has foo
written in it.
why so? , how can print backspace character standard output when set file.
update: please note - foo
followed space in outfile. why that?
computers tend represent text using distinct numbers each character - example, using ascii convention in character numeric value 8 backspace, upper case letters start 65, lower case 97 etc.... so, program generating 4 characters of output: f, o, o , backspace - on screen see f , o because terminal program interprets backspace command cursor , remove last-written character. if inspect outfile using program, may still see second o , backspace: example on linux cat -vt outfile
.
files don't have concept of interpreting backspaces commands remove earlier text, though if file's concatenated terminal later should operate same when program run without redirection file.
anyway, if want you'll need use file command seek 1 character truncate or overwrite there. can't done through shell redirection - need open , control file within program.
Comments
Post a Comment