简体   繁体   中英

The C language K&R Exercise 1-8

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 ?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM