积极答复者
C++ Win32控制台怎么检测回车

问题
答案
-
getchar有一个int型的返回值.当程序调用getchar时.程序就等着用户按键.用户输入的字符被存放在键盘缓冲区中.直到用户按回车为止(回车字符也放在缓冲区中).
新浪微博http://weibo.com/xianglitian,欢迎围观
- 已建议为答案 Helen Zhao 2012年5月7日 5:34
- 已标记为答案 Helen Zhao 2012年5月14日 7:56
-
#include <conio.h>
#include <stdio.h>int main( void )
{
while( !_kbhit() )
{
//
}
int nChar = _getch();
if(0x0D == nChar)
{
printf("Enter key is press!\n");
}
}Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.
- 已建议为答案 Helen Zhao 2012年5月7日 5:34
- 已标记为答案 Helen Zhao 2012年5月14日 7:56
-
用getchar接收字符,将接收到的字符与0D比较,0D就是回车的ASCII码。
下面是检测的代码
#include <stdio.h> ... ... ... char c ; c = getchar () ;//获取方法很多,这只是举个例子 if (0x0d == c) ;//作出你要的操作
- 已标记为答案 Helen Zhao 2012年5月14日 7:56
全部回复
-
getchar有一个int型的返回值.当程序调用getchar时.程序就等着用户按键.用户输入的字符被存放在键盘缓冲区中.直到用户按回车为止(回车字符也放在缓冲区中).
新浪微博http://weibo.com/xianglitian,欢迎围观
- 已建议为答案 Helen Zhao 2012年5月7日 5:34
- 已标记为答案 Helen Zhao 2012年5月14日 7:56
-
#include <conio.h>
#include <stdio.h>int main( void )
{
while( !_kbhit() )
{
//
}
int nChar = _getch();
if(0x0D == nChar)
{
printf("Enter key is press!\n");
}
}Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.
- 已建议为答案 Helen Zhao 2012年5月7日 5:34
- 已标记为答案 Helen Zhao 2012年5月14日 7:56
-
用getchar接收字符,将接收到的字符与0D比较,0D就是回车的ASCII码。
下面是检测的代码
#include <stdio.h> ... ... ... char c ; c = getchar () ;//获取方法很多,这只是举个例子 if (0x0d == c) ;//作出你要的操作
- 已标记为答案 Helen Zhao 2012年5月14日 7:56