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 ...
随机推荐
- HDU1869---(最短路+floyd)
http://acm.hdu.edu.cn/showproblem.php?pid=1869 思路:最短路+floyd 分析:1 题目是要求所有的数据能否满足“六度分离”,那么我们就想到所有点之间的最 ...
- Spring学习之路——单例模式和多例模式
在Spring中,bean可以被定义为两种模式:prototype(多例)和singleton(单例) singleton(单例):只有一个共享的实例存在,所有对这个bean的请求都会返回这个唯一的实 ...
- bzoj2683/4066 简单题
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2683 http://www.lydsy.com/JudgeOnline/problem.ph ...
- [bzoj1009][HNOI2008]GT考试——KMP+矩阵乘法
Brief Description 给定一个长度为m的禁止字符串,求出长度为n的字符串的个数,满足: 这个字符串的任何一个字串都不等于给定字符串. 本题是POJ3691的弱化版本. Algorithm ...
- 在ubuntu 上面安装ubuntu touch 模拟器
Canonical 公司已经发布了一个运行着Unity8和Mir的Ubuntu Touch模拟器.虽然有一些bug,例如在64位的系统上会使系统崩溃,但我们相信这些都会被一 一修复,这篇文章将教大家如 ...
- Multi-Paxos协议日志同步应用
使用Multi-Paxos协议的日志同步与恢复 基于Basic-Paxos协议的日志同步方案, 所有成员的身份都是平等的, 任何成员都可以提出日志持久化的提案, 并且尝试在成员组中进行持久化. 而在实 ...
- Spring MVC的静态和动态概念
MVC模式: 图释:用户请求通过HTTP协议到达Front controller,Front controller把请求送给Controller,Controller了解业务逻辑细节并且调用业务逻辑数 ...
- 学习struts2
有部分内容转载牛人的博客: http://blog.csdn.net/hudie1234567/article/details/6730481 http://blog.csdn.net/lishuan ...
- 手机端 输入法出现 input框不在屏幕中间位置的问题
/** * 修改点击input输入框时的位置 */ $('.input-footer-none').on('focus',function(){ var _this=this; setTimeout( ...
- 简单unix 局域网的TCP会话
client.c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <e ...