[TUHS] Literal character escapes in v7

Dan Cross crossd at gmail.com
Tue Nov 7 21:21:55 AEST 2017


On Mon, Nov 6, 2017, 11:21 PM Will Senn <will.senn at gmail.com> wrote:

> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://minnie.tuhs.org/pipermail/tuhs/attachments/20171107/530b2ff6/attachment.html>


More information about the TUHS mailing list