转: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?的更多相关文章

  1. SH Script Grammar

    http://linux.about.com/library/cmd/blcmdl1_sh.htm http://pubs.opengroup.org/onlinepubs/9699919799/ut ...

  2. 暴力枚举N级子域名

    #!/usr/bin/env python# -*- encoding: utf-8 -*-# A simple and fast sub domains brute tool for pentest ...

  3. windows 下使用 zip安装包安装MySQL 5.7

    以下内容参考官方文档:http://dev.mysql.com/doc/refman/5.7/en/windows-start-command-line.html 解压缩zip到D:\mysql-5. ...

  4. 【练习】显示MYSQL客户机选项

    [oracle@enmo ~]$ mysql --help mysql Ver , for Linux (x86_64) using EditLine wrapper Copyright (c) , ...

  5. hive-site.xml 参数设置

    <?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="confi ...

  6. Unix Shells: Bash, Fish, Ksh, Tcsh, Zsh

    Hyperpolyglot Unix Shells: Bash, Fish, Ksh, Tcsh, Zsh grammar | quoting and escaping | charactersvar ...

  7. Python3 栈的实现

    这篇博客主要记录我在学习python算法时实现栈的过程,这里栈的实现只是最简单的实现,其中也包括符号匹配,前缀.中缀以及后缀表达式的实例.参考书目为: problem-solving-with-alg ...

  8. Matplotlib学习笔记(二)

    原  Matplotlib学习笔记 参考:Python数据科学入门教程 Python3.6.1 jupyter notebook .caret, .dropup > .btn > .car ...

  9. Matplotlib学习笔记(一)

    原   matplotlib学习笔记 参考:Python数据科学入门教程 Python3.6.1 jupyter notebook .caret, .dropup > .btn > .ca ...

随机推荐

  1. 转:强化学习(Reinforcement Learning)

    机器学习算法大致可以分为三种: 1. 监督学习(如回归,分类) 2. 非监督学习(如聚类,降维) 3. 增强学习 什么是增强学习呢? 增强学习(reinforcementlearning, RL)又叫 ...

  2. 调整文本输入框placeholder的颜色等样式

    input::-webkit-input-placeholder{     color: white !important;}input:-moz-placeholder{    color: whi ...

  3. 【20160815】noip模拟(未完)

    #include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #inc ...

  4. 利用ES6的Promise.all实现至少请求多长时间

    1.背景 我们都知道ajax请求可以加个timeout,就是最多请求多少时间,如果超过这个时间直接就报错. 这个是最多请求多长时间,我现在要做的是,最少要请求多长时间,然后才能执行后续的逻辑. 比如, ...

  5. bzoj 1601 最小生成树

    原题传送门http://www.lydsy.com/JudgeOnline/problem.php?id=1601 最小生成树的比较水的题,我们只需要加一个源点,连向所有的点,边权为每个点建水库的代价 ...

  6. python3 基础概念

    一.3.x新特性 1.print (),打印,3.x必须加括号 2.raw_input,3.x改为input   二.简介   Python是著名的“龟叔”Guido van Rossum在1989年 ...

  7. AOP相关

    静态代理.动态代理与AOP: 简单易懂:http://blog.csdn.net/hejingyuan6/article/details/36203505 补充:http://layznet.itey ...

  8. 用java实现word转html

    由于项目需要,要完成将上传的word文件转成html文件的功能.在网上搜了一下,大致有3种方法:1.用jacob实现 2.用poi实现 3.用openoffice实现. 从网上来看好像jacob用的人 ...

  9. 【C++】默认构造函数

    参考文献: 1.黄邦勇帅 2.http://www.cnblogs.com/graphics/archive/2012/10/02/2710340.html 3.http://blog.csdn.ne ...

  10. window下golang包管理glide使用说明

    golang是一门简洁高效的开发 语言,但是包管理一直是一个痛点,如图 : 很多开源项目特别是github.com中的大量应用golang.org和google.golang.org中的源码,且由于被 ...