Reputation: 207
I sitting right now on K&R The C programming Language . and i have stack on 1 Exercise 1-8 .
The Exercise it self.
Write a program to replace each tab by three-character sequence >, backspace, -, witch prints as →, and each backspace by the similar ←. This makes tabs and backspaces visible.
As i understand here that exercise ask me to make pointing arrows in tabs and backspaces. But i cant get how to clip 2 characters together in C
Here is program it self
#include <stdio.h>
main ()
{
int c;
while ((c=getchar()) !=EOF)
{
if (c == '\t')
printf(">->->\b");
if (c == '\b')
printf("<-<-<-\b");
if (c !='\t')
if (c !='\b')
putchar(c);
}
getchar();
}
So where is my mistake can you help me here ?
Upvotes: 0
Views: 827
Reputation: 179392
The sequence desired is
>\b-
Note that this may not work on modern terminal emulators, since most do not support overprinted characters. The original idea was to mimic the old typewriter technique of printing a character, backing the head up by one character, and striking another character over top of the previous one.
If your terminal supports UTF-8, you can substitute the '→' Unicode glyph (U+2192 RIGHTWARDS ARROW), which is encoded in UTF-8 as
\xe2\x86\x92
Similarly, '←' (U+2190) is
\xe2\x86\x90
Upvotes: 3