发新话题
打印

[C] getch()的用法

getch()的用法

#include <stdio.h>  
void main()  
{  
char letter;  
printf("please input the first letter of someday\n");  
while((letter=getch())!='Y')  
{switch(letter)  
{case 's':printf("please input second letter\n");  
if((letter=getch())=='a')  
printf("saturday\n");  
else if((letter=getch())=='u')  
printf("sunday\n");  
else printf("data error\n");  
break;  
case 'f':printf("friday\n");break;  
case 'm':printf("monday\n");break;  
case 't':printf("please input second letter\n");  
if((letter=getch())=='u')  
printf("tuesday\n");  
else if((letter=getch())=='h')  
printf("thursday\n");  
else printf("data error\n");  
break;  
case 'w':printf("wednesday\n");break;  
default:printf("data error\n");  
}}}  
这里面的getch()是做什么用的啊?
为什么我去掉了就不能运行if里的语句了?

[ 本帖最后由 Liangent 于 2008-10-12 16:14 编辑 ]

TOP

:s027: :s033: :s033: :s033: 标题党
举世誉我而不加劝 举世非我而不加沮
http://hi.baidu.com/sruingking

TOP

获得从键盘的一个字符的输入 但不显示在屏幕上

和getchar的区别
getchar
This is a standard function that gets a character from the stdin.

getch
This is a nonstandard function that gets a character from keyboard, does not echo to screen.

[ 本帖最后由 fwoncn 于 2008-9-23 10:06 编辑 ]
本帖最近评分记录
  • Liangent 现金 +12 我很赞同,加分鼓励 2008-9-23 12:41

TOP

回复 3楼 的帖子

getchar会等待回车
在conio.h中

TOP

TS
把conio.h加进去

TOP

getch从键盘读数据,不从键盘缓冲去读数据,getch读数据不显示

TOP

回复 1楼 的帖子

你学的是c语言还是c++,这里的geth()是一个库函数,在c++“conio.h”,这是从读取键盘上的一个键,如果去掉了,letter就没有赋值了,所以就不能运行。

TOP

发新话题