linux 画图程序测试三

该程序显示字符左右移动

 

/**
* curses3.c
*/
#include
<stdio.h>
#include
<curses.h>
#include
<sys/ioctl.h>
#include
<signal.h>
void restandend();
int main(int ac,char *av[])
{
struct winsize wbuf;
int rows,cols;
int dir=+3,pos=0;
//signal(SIGINT,restandend);
if(ioctl(0,TIOCGWINSZ,&wbuf)!=-1)
{
        rows
=wbuf.ws_row;
        cols
=wbuf.ws_col;
}
rows
=10;
//printf("row=%d col=%d\n",rows,cols);
initscr();
while(1)
{
        move(rows,pos);
        addstr(
"cartoon");
        
if(pos>(cols-9&& dir==+3)
                dir
=-3;
        
if(pos<=0 && dir==-3)
                dir
=+3;
        sleep(
1);
        refresh();
        move(rows,pos);
        addstr(
"       ");
        pos
+=dir;
}
standend();
return 0;
}
void restandend()
{
move(
0,0);
addstr(
"exit");
refresh();
standend();
exit(
1);
}

 

posted on 2009-04-05 18:36  ringwang  阅读(449)  评论(0编辑  收藏  举报