您的位置:程序门 -> linux/unix社区 -> 系统维护与使用区



请问linux下的c语言中怎样按键盘的任意键以后继续执行


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


请问linux下的c语言中怎样按键盘的任意键以后继续执行[已结贴,结贴人:liuyu85]
发表于:2007-06-26 15:47:40 楼主
请问linux下的c语言中怎样按键盘的任意键以后继续执行?
我已经找了很久,全都是windows下的getch()函数,在linuxx中根本就不能用,使用getchar()函数   需要按回车才有反应,不能达到按任意键继续的功能,情大侠们帮助我一下,谢谢了!
发表于:2007-06-26 16:27:591楼 得分:0
getchar   不能用?
发表于:2007-06-27 00:28:252楼 得分:0
终端在raw模式下getchar才能达到楼主需要的效果.
发表于:2007-06-27 08:45:303楼 得分:0
getch()可以用呀
不过它是控制台函数,需要你一定的设置

#include   <stdio.h>
#include   <curses.h>
main()
{
int   i;
initscr();
for(i=0;i <lines;i++)
{
  move(i,i+i);
  if(i%2==1)
      standout();
  addstr( "hello,word ");
  if(i%2==1)
    standend();
}
refresh();
getch();
endwin();
}

~
makefile:
hello:hello.c
                gcc   -g   hello.c   -lcurses   -o   hello
clean:
                rm   -f   *.c~   hello
发表于:2007-06-27 09:52:484楼 得分:20
回楼上:想了一下,是我表达的意思有问题,我本意是“getchar只有当终端在raw模式下才能达到楼主需要的效果”

楼上用curses实现!
来一个用raw终端方式的:
#include   <stdio.h>
#include   <stdlib.h>

int   main(void)
{

        system( "stty   raw   -echo ");
        printf( "press   any   key   to   continue   .   .   .   ");
        getchar();
        system( "stty   -raw   echo ");
        printf( "\n ");
        return   0;
}
发表于:2007-06-27 10:24:135楼 得分:0
楼上两位已经覆盖全部了....   我只能顶了


快速检索

最新资讯
热门点击