I wrote a snippet from my K&R C studies to convert tabs and backspaces
to \t \b to display them, the code looks like this:
/* ex 1-8 */
main()
{
int c, sf;
while((c = getchar()) != EOF) {
if(c == '\t')
printf("\\t");
if(c == '\b')
Shouldn't this be 'else if'? Otherwise, if you encounter a tab, you will print '\t' and then call into the 'else' below after the test for '\b' and print c, which is a tab literal.
- Dan C.
printf("\\b");
else
putchar(c);
}
}
I'm not looking for code review, but the code is intended to replace the
tabs and backspaces with \t and \b respectively, but I haven't been able
to test it because I can't seem to make a backspace character appear in
input. In later unices, ^V followed by the backspace would work, but
that's not part of v7. Backspace itself is my erase character, so
anytime I just type it, it backspaces :).
Thanks,
Will
--
GPG Fingerprint: 68F4 B3BD 1730 555A 4462 7D45 3EAA 5B6D A982 BAAF