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 ...
随机推荐
- 【BZOJ3670】【NOI2014】动物园 [KMP][倍增]
动物园 Time Limit: 10 Sec Memory Limit: 512 MB[Submit][Status][Discuss] Description 近日,园长发现动物园中好吃懒做的动物 ...
- Nodejs写的搬家工具知识分享
这篇文章 主要学习这两个模块的使用: request-promise-native : https://github.com/request/request-promise-native cheeri ...
- DB 基本性能指标
DB: •500K I/O limit with kill(5M I/O limit for DWS) •10,000 return row limit with kill •30 seconds p ...
- 转:Android 的一些比较好的开源代码项目
转自:http://blog.csdn.net/zengyangtech/article/details/7019439 Android PDF 阅读器 http://sourceforge.net/ ...
- Windows下搭建本地SVN服务器【转】
转自:http://www.linuxidc.com/Linux/2015-01/111563.htm 本文介绍Windows下搭建本地SVN服务器的方法,网上资料比较少也比较旧,大都介绍的是旧版本S ...
- Js使用WScript.Shell对象执行.bat文件和cmd命令
Js使用WScript.Shell对象执行.bat文件和cmd命令 http://www.jb51.net/article/58669.htm WScript.Shell(Windows Script ...
- PL/SQL 04 游标 cursor
--游标 declare cursor 游标名字 is 查询语句;begin 其他语句;end; --游标的属性%FOUND%NOTFOUND%ISOPEN%ROWCOUNT(当前游标的指针位 ...
- Selenium2+python自动化73-定位的坑:class属性有空格【转载】
前言 有些class属性中间有空格,如果直接复制过来定位是会报错的InvalidSelectorException: Message: The given selector u-label f-dn ...
- jquery插件需要明白的那些知识点
1.jquery中$是神马?$.fn又是神马? 稍微有jquery经验的都知道在jquery中$等价于jQuery,在控制台一试便知: 我们在jquery(1.8.3)源码中也能找到下面代码: 其实在 ...
- centos 修改ftp目录
# usermod -d /home/www username // # service vsftpd restart // 重启vsftpd 两步搞定