转: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. 【BZOJ4080】【WF2014】Sensor Network [随机化]

    Sensor Network Time Limit: 2 Sec  Memory Limit: 128 MB[Submit][Status][Discuss] Description 魔法炮来到了帝都 ...

  2. Bzoj4197 寿司晚宴

    Description 为了庆祝 NOI 的成功开幕,主办方为大家准备了一场寿司晚宴.小 G 和小 W 作为参加 NOI 的选手,也被邀请参加了寿司晚宴. 在晚宴上,主办方为大家提供了 n−1 种不同 ...

  3. vc6.0里使用lib(静态库)的方法

    vc6.0 中使用lib文件 使用库的方法如下:1. 包含库的头文件(把库的头文件包含到项目中)在应用程序工程中使用#include "file path"file path可以为 ...

  4. Python小程序之用户登陆接口

    编写登陆接口 输入用户名密码 认证成功后显示欢迎信息 输错三次后锁定 程序逻辑图: 代码: #!/usr/bin/env python #_*_ coding:UTF-8 _*_ #__author_ ...

  5. CHM文件出现的常见错误及解决办法

    一.chm文件内容乱码: 解决方式:将IE浏览器的编码换成自动选择,或者选择UTF-8和GBK看那个能使用.因为chm文件默认的是IE浏览器的内核. 二.easy chm软件编译文件时左侧索引乱码,源 ...

  6. jQuery 立即执行

    ;(function($){// 可以去掉开头的 ; (分号),国外的开发人员编写的插件时的一种习惯 $.fn.pluginName = function() { // Our plugin impl ...

  7. 浅谈C#多线程与UI响应

    www.educity.cn     发布者:shenywww                    来源:网络转载                     发布日期:2014年10月06日      ...

  8. 使用httpclient异步调用WebAPI接口

    最近的工作需要使用Bot Framework调用原有的WebAPI查询数据,查找了一些方法,大部分都是使用HttpClient调用的,现时贴出代码供参考 using System; using Sys ...

  9. python 面向对象(成员,静态,类)的(变量,方法)区别

    静态方法是使用@staticmethod装饰的方法,并且参数表中不需要self或者cls,可以访问类成员变量 默认的方法是有self的,是成员方法,可以访问私有变量和方法(通过self.xxx),或者 ...

  10. boost::operators

    boost 的 operators 提供了comparison operators.arithmetic operators.operators for iterators 操作.虽然使用 C++ 的 ...