利用curses库编程开始
2013-06-24 00:06
169 查看
curses库常用函数:
注意编译时要用这样的格式:gcc xxx.c -l curses -o xxx
第一个小例子:
第二个小例子:
第三个小例子:
第四个小例子:
注意编译时要用这样的格式: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库编程开始
- 开始利用CSDN做学习笔记,从windows 游戏编程大师技巧和3D游戏编程大师开始
- 如何利用Python和win32编程避免重复性体力劳动(一)——开始、FindWindow和FindWindowEx
- 如何利用Python和win32编程避免重复性体力劳动(一)——开始、FindWindow和FindWindowEx
- 写给四年前刚开始编程的自己
- [转] 写给四年前刚开始编程的自己
- 利用C#进行Socket通信编程之一
- linux下通过利用qcreator实现简单界面编程
- 熬之滴水穿石:一切从windows编程开始(4)
- 开始学习Web编程
- Linux下c语言的图形编程(转) curses.h 函式库
- 90页第三题,创建一个 Rectangle类,添加width和lenght两个成员变量 在 Rectangle类中添加两种方法分别计算矩形的周长和面积 ,编程利用Rectangle输出一个矩形的
- 开始我的windows编程
- 怎样开始学习编程?
- 安装Python的web.py框架并从hello world开始编程
- 利用递归函数求奇数连乘的积(递归有点难,刚开始不理解)
- 利用JMF进行多媒体编程
- 如何利用VB.NET网页上编程计数器方法?
- 今天起,正式开始编程之路
- 【zz】免费的午餐——编程利用Google日历API发短信、Email