The relationship between the shell and program C

I wrote the following code as part of the exercise in the first chapter of K & R. The code replaces tabs and backslashes as expected, but does not replace backspaces with \ b. Here is the code:

#include <stdio.h>


int main(void)
{
    int c;

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

        if (c == '\b')
        {
            //putchar('\\');
            //putchar('b');
            printf("\\b");
        }

        if (c == '\\')
        {
            putchar('\\');
            putchar('\\');
        }

        if (c != '\t' && c != '\b' && c != '\\')
        {
            putchar(c);
        }
    }


    return 0;
}

Stack Overflow. , backspace, , , , backspace. : , ? , stdin. , , , , . - , ? , , stdin ?

, . , , , , .

+4
2

getchar() , , ENTER. , .

"", "" "" ENTER, " " ENTER.

(.. ./myprog < input_file) (.. ./otherprog | ./myprog), getchar , , UTF-8.

+3

, backspace getchar . backspace, , .

, , .

+1

Source: https://habr.com/ru/post/1680832/


All Articles