1.getch()这个函数可以让用户按下任意键而不需要回车就可以接受到用户的输入。可以用来作为“press any key to continue”的实现
int getch(void)
{return (bufp>0) ? buf(--bufp) : getchar();
}
下面是示例代码
#include <stdio.h>
#include <conio.h>
int main(void)
{
char ch;
printf("Input a character:");
ch = getch();
printf("\nYou input a '%c'\n", ch);
return 0;
}
2.ungetch() 功 能: 把一个字符退回到键盘缓冲区中
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
int main( void )
{
int i=0;
char ch;
puts("Input an integer followed by a char:");
/* read chars until non digit or EOF */
while((ch = getche()) != EOF && isdigit(ch))
i = 10 * i + ch - 48; /* convert ASCII into int value */
/* if non digit char was read, push it back into input buffer */
if (ch != EOF)
ungetch(ch);
printf("\n\ni = %d, next char in buffer = %c\n", i, getch());
return 0;
}
void ungetch(int c)
{
if(bufp>=BUFSIZE)
printf("ungetch:too many charactors\n");
else
buf[bufp++]=c;
}