4
#include <stdio.h>
main()
{
    int c;
    while ((c = getchar()) != EOF) {
        if (c == '\t') {
            putchar('\\');
            putchar('t');
        }
        if (c == '\b') {
            putchar('\\');
            putchar('b');
        }
        if (c == '\\') {
            putchar('\\');
            putchar('\\');
        }
        if (c != '\t')
            if (c != '\b')
                if (c != '\t')
                    putchar(c);
    }
}

My question is - why can't i see the \b output? I'm currently learning K&R C and using Windows 10. I can't get a \b symbol in the Windows command line, while on Ubuntu it works pretty much ok. I've tried CTRL + H, but still no \b. Is there a way to fix this?

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
  • Why do you desperately want to input a backspace? – klutt Nov 06 '19 at 12:43
  • 1
    Very likely your application doesn't get the backspace, as the console program is handling it itself. – Some programmer dude Nov 06 '19 at 12:43
  • 5
    On another (and unrelated) note, your code could be cleaner with a `switch` statement, where last nested `if` would be the `default` case. – Some programmer dude Nov 06 '19 at 12:44
  • 1
    @Someprogrammerdude Doesn’t even need to be a `switch`, a simple `else if` would suffice. – Konrad Rudolph Nov 06 '19 at 12:50
  • How are you launching the application? In particular, how are you feeding it input, and what’s the input? – Konrad Rudolph Nov 06 '19 at 12:51
  • 2
    Does this answer your question? [how to check for the "backspace" character in C](https://stackoverflow.com/questions/4363309/how-to-check-for-the-backspace-character-in-c) – Sander De Dycker Nov 06 '19 at 12:52
  • 1
    If you want to get unprocessed keyboard input you could use function `getch` from `ncurses` or (non-portable, DOS/Windows only) `getch`/`_getch` from `conio.h` See also https://stackoverflow.com/a/4028974/10622916 – Bodo Nov 06 '19 at 13:04

0 Answers0