scanf
读到空格,制表符,回车为止,把缓存区的"\0"前的所有字符一次性读取。
gets
char *gets( char *buffer );
The line consists of all characters up to and including the first newline character ('\n'). gets then replaces the newline character with a null character ('\0') before returning the line.
从流里读取一行,与scanf的区别是读一整行,空格也会读进,只有读到\n才停止,\n也会拿走。
终止后,对终止字符处理不同。
比如输入为"test\nabcd"。
执行gets后,\n不会留在缓冲区中,即这时调用getchar得到的字符是'a'。
执行scanf后,\n会留在缓冲区,这时调用getchar得到的字符是'\n'。
getchar
一次从缓存区拿一个字符。
getch
包含在头文件<conio.h>里。
getch从键盘接收一个字符并且不打印在屏幕上,不需要按下回车即可获取键盘输入,游戏函数常用。
问题:getch()和_getch()的区别?