From mboxrd@z Thu Jan 1 00:00:00 1970 From: crossd@gmail.com (Dan Cross) Date: Tue, 07 Nov 2017 11:21:55 +0000 Subject: [TUHS] Literal character escapes in v7 In-Reply-To: References: Message-ID: On Mon, Nov 6, 2017, 11:21 PM Will Senn 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: