Questions tagged «unbuffered»

12
如何避免使用getchar()按下Enter键仅读取单个字符?
在下面的代码中: #include <stdio.h> int main(void) { int c; while ((c=getchar())!= EOF) putchar(c); return 0; } 我必须按Enter来打印输入的所有字母getchar,但是我不想这样做,我要做的是按字母,然后立即看到我介绍的字母重复,而无需按Enter。例如,如果我按字母“ a”,我想在其旁边看到另一个“ a”,依此类推: aabbccddeeff..... 但是,当我按“ a”时,什么也没发生,我可以写其他字母,并且只有在按Enter以下命令时,副本才会出现: abcdef abcdef 我怎样才能做到这一点? 我cc -o example example.c正在Ubuntu下使用命令进行编译。
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.