Linux下实现“任意键继续”
来源:互联网 发布:小米电动牙刷 知乎 编辑:程序博客网 时间:2024/06/05 10:11
因为getch()函数不回显,并在终端输入不需要回车。所以可在很多程序灵活运用
以下为摘录网络上的代码:
#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
#include <unistd.h>
int getch();
void press_key();
int main()
{
printf("Hello world!\n");
press_key();
return 0;
}
void press_key()
{
printf("Press any key to continue...\n");
getch();
}
int getch()
{
struct termios tm, tm_old;
int fd = STDIN_FILENO,c;
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;
}
#include <stdlib.h>
#include <termios.h>
#include <unistd.h>
int getch();
void press_key();
int main()
{
printf("Hello world!\n");
press_key();
return 0;
}
void press_key()
{
printf("Press any key to continue...\n");
getch();
}
int getch()
{
struct termios tm, tm_old;
int fd = STDIN_FILENO,c;
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;
}
0 0
- Linux下实现“任意键继续”
- linux下C语言实现按任意键继续~~
- C++ 实现按任意键继续~~~
- 用C++实现“按任意键继续”
- 怎么砸linux先c语言中实现按任意键继续~~
- VCL开发时实现按任意键继续
- Unix批处理(.sh)中 实现按任意键继续
- [C++] 用C++实现“按任意键继续”
- BASH中用 read 实现“按任意键继续”
- Linux 按任意键继续而不必等回车
- Linux 下 Python 实现按任意键退出
- golang 按任意键继续
- linux 下停止,继续进程
- linux下使用glob()实现打开任意目录下的所有文件
- 写控制台程序时,显示 请按任意键继续...
- 4.Linux下nohup命令实现退出终端后程序继续后台运行
- linux shell下利用bc,实现任意进制的转换
- Console:输入任意字符继续。。。
- linux基础
- (15.1.5)无聊的时候我们就去翻妹子们的微博
- iOS开发系列--视图切换
- RandomAccessFile使用
- WIN7(64位)安装Python模块py-radix
- Linux下实现“任意键继续”
- 基于特征值的斐波那契数列求解
- eclipse如何修改dynamic web module version
- (15.1.5.1)【涨姿势】如何用大数据思维勾搭到大胸萌妹纸
- FragmentPagerAdapter与FragmentStatePagerAdapter区别
- 第十一周 阅读程序(1)
- iOS开发系列--UITableView全面解析
- 机器学习基础知识
- 第5章