丰田致炫2015款报价:C语言问题

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/07 07:27:21
在循环中如何达到按“ESC”键实现break的功能。按“空格键”实现continue功能。而且在等待按键的过程中,其他普通按键(如字母键,数字键)都失效。

#include <stdio.h>

int main(void)
{
int ch;

while(1){
ch=getch(stdin);
/*按下ESC键的时候*/
if(ch==27){
break;
}
/*按下其它键的时候在屏幕上显示按下的ASCII码值*/
printf("[%d]\n",ch);
}
return 0;
}

运行.exe时,ESC 另有用途,C 程序不能用。
可以改用*号或别的号。

#include <stdio.h>
void main()
{
unsigned char ch;
int x = 0;

while( x == 0){
ch=getchar();
if(ch== 0x2a) // *号编码是 0x2a
{
x = 1;
}
printf(\"[%d]\\n\",ch); // 非*号,继续在while 中循环。
}
}

ESC和break键
在程序中用在ASCII码里面的编码

用选择语句!11

用if 语句