getchar and putchar

后端 未结 6 1977
耶瑟儿~
耶瑟儿~ 2021-02-06 14:40

My C code:

int c;
c = getchar();

while (c != EOF) {
    putchar(c);
    c = getchar();
}

Why does this program react like this on inputting

6条回答
  •  一整个雨季
    2021-02-06 15:08

    Your terminal probably only writes your input to stdin when you press enter. Try typing something, backspace and write something else; if you don't see the originally typed characters, it means that your terminal was waiting for you to compose the line before sending the data to the program.

    If you want raw terminal access (e.g. react to key-down and key-up), you should try some terminal library like ncurses.

提交回复
热议问题