Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How come \b is not recognized from ex. 1-10 in K&R?

#include <stdio.h>
/* replace tabs and backspaces with visible characters */

main()

{
    int c;

    while ((c = getchar()) != EOF) {
        if (c == '\t')
            printf("\\t");
        if (c == '\b')
            printf("\\b");
        if (c == '\\')
            printf("\\\\");
        if (c != '\b')
            if (c != '\t')
                if (c != '\\')
                    putchar(c);
    }
}

Why was I not able to see \b backspace signature when I press the backspace?

like image 713
Joseph Lee Avatar asked Dec 05 '25 02:12

Joseph Lee


1 Answers

You need to learn about else, that if-ladder is pretty scary.

And your terminal probably doesn't send a single backspace character, it can be a bit complicated how actual terminal programs represent that kind of "special" key (delete is another favorite).

like image 63
unwind Avatar answered Dec 07 '25 15:12

unwind