按任意键返回(退出)

来源:互联网 发布:mac outlook 默认字体 编辑:程序博客网 时间:2024/05/20 23:57
#include <stdio.h>#include <termios.h>#include <unistd.h>int getch(){    struct termios tm,tm_old;    int fd = STDIN_FILENO,c;setbuf(stdin,NULL);     if (tcgetattr(fd, &tm) < 0)    {        return -1;    }     tm_old = tm;    cfmakeraw(&tm);     if (tcsetattr(fd,TCSANOW, &tm) < 0)    {        return -1;    }     c = fgetc(stdin);     if (tcsetattr(fd,TCSANOW,&tm_old) < 0)    {        return -1;    }    return c;}int main(){system("clear");printf("按任意键退出。。。\n");getch();return 0;}

0 0
原创粉丝点击