利用curses库编程开始
来源:互联网 发布:2016大学生网购数据 编辑:程序博客网 时间:2024/06/05 01:06
curses库常用函数:
注意编译时要用这样的格式:gcc xxx.c -l curses -o xxx
第一个小例子:
include <stdio.h>#include <curses.h>int main(){ initscr(); clear(); move(10,20); addstr("Hello, world"); move(LINES-1, 0); refresh(); getch(); endwin(); return 0;}运行效果如下:
第二个小例子:
#include <stdio.h>#include <curses.h>int main(){ int i; initscr(); clear(); for (i = 0; i < LINES; i++) { move(i, i+1); if (i%2 == 1) standout(); //反白显示 addstr("Hello, world"); if (i%2 == 1) standend(); //关闭反白显示 } refresh(); getch(); endwin(); return 0;}运行效果:
第三个小例子:
#include <stdio.h>#include <curses.h>int main(){ int i; initscr(); clear(); for (i = 0; i < LINES; i++) { move(i, i+1); if (i%2 == 1) standout(); addstr("Hello, world"); if (i%2 == 1) standend(); refresh(); sleep(1); move(i, i+1); //move back addstr(" "); //erase the line appear before } endwin(); return 0;}运行效果:字符串沿着对角线一行一下行的向下移动
第四个小例子:
#include <stdio.h>#include <curses.h>#define LEFTEDGE 10 /* 左边界 */#define RIGHTEDGE 30 /* 右边界 */#define ROW 10 int main(){ char *message = "Hello"; char *blank = " "; int dir = 1; int pos = LEFTEDGE; initscr(); clear(); while (1) { move(ROW, pos); addstr(message); /* draw string */// move(LINES-1, COLS-1); refresh(); /* show string */ sleep(1); move(ROW, pos); /* move back */ addstr(blank); /* erase string */ pos += dir; /* advance position */ if (pos >= RIGHTEDGE) /* check for bounce */ dir = -1; if (pos <= LEFTEDGE) dir = 1; } return 0;}运行效果:在(ROW,LEFTEDGE)----(ROW,RIGHTEDGE)间来回移动字符串
- 利用curses库编程开始
- curses库的编程
- linux中curses库编程
- linux下的c 编程------curses 库
- linux下的图形编程库curses
- Curses库
- curses编程(一)初识
- Linux中的curses编程
- curses编程初识
- 键盘输入curses编程
- linux-curses界面编程
- 利用curses来创建窗口
- [Linux系统编程]Curses编程
- 可爱的 Python:Curses 编程
- curses编程初步--汉诺塔游戏
- Linux curses库
- Linux curses库使用
- curses 库例子
- CCNA学习笔记2-TCP/IP协议栈
- 蚁群算法
- CCNA学习笔记3-IP地址+子网划分
- CCNA学习笔记4-安装Cisco设备
- 06-将整型值转换为字符串(字符串处理)
- 利用curses库编程开始
- Class对象
- 一个计算机专业学生几年的Java编程经验汇总
- Android中的Intent详细讲解
- 教你恢复硬盘格式化的数据
- 个人小项目——飞聊通讯录V1.0小结
- 事务
- poj 2778 DNA Sequence
- 泛型