c语言出入字符后跳出循环的提问

来源:百度知道 编辑:UC知道 时间:2024/06/04 17:46:53
#include "stdio.h"
void main()
{
int a=0;
for(;;)
{
a++;
printf("%d\n",a);
if(********)break;
}
}

这个程序是这样的 : 如果键盘没有输入字符,会无限循环
结束循环的唯一方法是在if的条件中写上(如果键盘输入字符)

我希望这个程序运行时是这样的 :
首先 开始: 然后屏幕会不断循环显示 a的值 (从0到32767 然后有从-32768到32767) 不停的循环 当你在键盘上输入任何一个字符的时候 就会跳出循环 请问应该怎么写?

不知道的不要插话哦! 谢谢

Checks the console for keyboard input.

int _kbhit( void );
/* KBHIT.C: This program loops until the user
* presses a key. If _kbhit returns nonzero, a
* keystroke is waiting in the buffer. The program
* can call _getch or _getche to get the keystroke.
*/

#include <conio.h>
#include <stdio.h>

void main( void )
{
/* Display message until key is pressed. */
while( !_kbhit() )
_cputs( "Hit me!! " );

/* Use _getch to throw key away. */
printf( "\nKey struck was '%c'\n", _getch() );
_getch();
}

结束循环的唯一方法是在if的条件中写上(如果键盘输入字符) ----c是按行执行的,怎么可能同时输出又输入

if(getch())