Getting terminal width in C?
转:http://stackoverflow.com/questions/1022957/getting-terminal-width-in-c
方法一:
#include <sys/ioctl.h>
#include <stdio.h> int main (void)
{
struct winsize w;
ioctl(, TIOCGWINSZ, &w); printf ("lines %d\n", w.ws_row);
printf ("columns %d\n", w.ws_col);
return ;
}
方法二:
#include <stdio.h>
#include <stdlib.h>
#include <termcap.h>
#include <error.h> static char termbuf[]; int main(void)
{
char *termtype = getenv("TERM"); if (tgetent(termbuf, termtype) < ) {
error(EXIT_FAILURE, , "Could not access the termcap data base.\n");
} int lines = tgetnum("li");
int columns = tgetnum("co");
printf("lines = %d; columns = %d.\n", lines, columns);
return ;
}
注意:Needs to be compiled with -ltermcap . There is a lot of other useful information you can get using termcap. Check the termcap manual using info termcap for more details.
Getting terminal width in C?的更多相关文章
- SH Script Grammar
http://linux.about.com/library/cmd/blcmdl1_sh.htm http://pubs.opengroup.org/onlinepubs/9699919799/ut ...
- 暴力枚举N级子域名
#!/usr/bin/env python# -*- encoding: utf-8 -*-# A simple and fast sub domains brute tool for pentest ...
- windows 下使用 zip安装包安装MySQL 5.7
以下内容参考官方文档:http://dev.mysql.com/doc/refman/5.7/en/windows-start-command-line.html 解压缩zip到D:\mysql-5. ...
- 【练习】显示MYSQL客户机选项
[oracle@enmo ~]$ mysql --help mysql Ver , for Linux (x86_64) using EditLine wrapper Copyright (c) , ...
- hive-site.xml 参数设置
<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="confi ...
- Unix Shells: Bash, Fish, Ksh, Tcsh, Zsh
Hyperpolyglot Unix Shells: Bash, Fish, Ksh, Tcsh, Zsh grammar | quoting and escaping | charactersvar ...
- Python3 栈的实现
这篇博客主要记录我在学习python算法时实现栈的过程,这里栈的实现只是最简单的实现,其中也包括符号匹配,前缀.中缀以及后缀表达式的实例.参考书目为: problem-solving-with-alg ...
- Matplotlib学习笔记(二)
原 Matplotlib学习笔记 参考:Python数据科学入门教程 Python3.6.1 jupyter notebook .caret, .dropup > .btn > .car ...
- Matplotlib学习笔记(一)
原 matplotlib学习笔记 参考:Python数据科学入门教程 Python3.6.1 jupyter notebook .caret, .dropup > .btn > .ca ...
随机推荐
- BroadCastRecieve
首先介绍一下BroadCastRecieve有几种: 1.无序广播(普通广播):sendBroadcast()方式 2.有序广播:sendOrderedBroadcast()方式 3.粘性广播:sen ...
- malloc和new的区别 begin
http://blog.csdn.net/miss_acha/article/details/7279915#comments 1.综述 1,malloc与free是C++/C语言的标准库函数,new ...
- servlet+forward和direct区别
Servlet:是用于 java 编写的服务器端程序,其使用 java servlet API,当客户机发送请求到服务器时,服务器可以将请求信息发送给 servlet,并让 servlet 建立起服务 ...
- Linux下挂载存储设备
1. 安装iscsi (文件iscsi-initiator-utils-6.2.0.871-0.10.el5.x86_64.rpm在系统光盘可以找到) rpm -ivh iscsi-initiat ...
- 深入理解Java的注解(Annotation):自定义注解入门(2)
要深入学习注解,我们就必须能定义自己的注解,并使用注解,在定义自己的注解之前,我们就必须要了解Java为我们提供的元注解和相关定义注解的语法. 元注解: 元注解的作用就是负责注解其他注解.Java5. ...
- TS 数据流分析学习
TS 流.包结构以及同步 1. TS 流: 可以将TS流理解为一种单一码流.混合码流. 单一码流:TS流的基本组成单位是长度为188字节的TS包. 混合码流:TS流有多种数据组成,一个TS包中的数据可 ...
- MAC使用homeBrew安装Redis
homeBrew的操作命令如下: brew search ** //查找某个软件包 brew list //列出已经安装的软件的包 brew install ** //安装某个软件包,默认安装的是稳定 ...
- .net开发CAD2008无法调试的解决方法
把acad.exe.config文件修改为:------------------------------------------------------------------------------ ...
- 【转】C#获取当前程序运行路径的方法集合
//获取当前进程的完整路径,包含文件名(进程名).string str = this.GetType().Assembly.Location;result: X:\xxx\xxx\xxx.exe (. ...
- Linux 下 UltraEdit 版本 破解 30 天试用限制
原创 http://yhz61010.iteye.com/blog/2319599 rm -rfd ~/.idm/uex rm -rf ~/.idm/*.spl rm -rf /tmp/*.spl 一 ...