藍森林首頁 | 返回主頁 | 本站地圖 | 站內搜索 | 聯繫信箱 |
 您目前的位置:首頁 > 自由軟件 > 技術交流 > 應用編程


    

藍森林 http://www.lslnet.com 2006年6月6日 10:18


curses問題-輸入字符時光標不移動為什麼?

我也寫了個curses 玩玩,就是在接收數據是光標老在一個位置,這是什麼原因?

[code]
#include <stdio.h>;
#include <stdlib.h>;
#include <curses.h>;


main()
{
        WINDOW *wptr;
        char buff[10];
                int i=0;
        char ch;

        initScr();
       

        wptr = newwin(40, 40, 0, 0);
        drawBox(2, 2, 20, 20, wptr);

        wmove(wptr, 5, 5);
        waddstr(wptr, "NAME: ");
        wmove(wptr, 5, 12);
        waddstr(wptr, "___________");

        echo();

        while(1) {

                int x=12, y=5;
                int i=0;
                int buff[12];

                ch = mvwgetch(wptr, y, x++);//接收下一個字符時橫坐標右移一位
                if (ch==13)
                        break;

                buff[i++]=ch;
        }


        refresh();
        getchar();

        endwin();
}

initScr()
{
   initscr();
   cbreak();
   nonl();
   noecho();

   intrflush(stdscr, FALSE);

   keypad(stdscr, TRUE);

   refresh();
}


drawBox(int x1, int y1, int rows, int cols, WINDOW *win)
{
    int i, x2;

    wattroff(win, A_REVERSE);
    wattrset(win, A_NORMAL);

        /* Head Line */
    mvwaddstr(win, y1, x1, "&?quot;);

    for(i=1; i<rows/2+1; i++)
        mvwaddstr(win, y1, x1+2*i, "&&");

    mvwaddstr(win, y1, x1+2*i, "&·");

        /* colnums */
    x2 = x1 + 2*i;
    for(i=1; i<= cols; i++)
    {
        mvwaddstr(win, y1+i, x1, "&§");
        mvwaddstr(win, y1+i, x2,"&§");
    }


    mvwaddstr(win, y1+i, x1, "&&");

    for(i=1; i<rows/2+1; i++)
        mvwaddstr(win, y1+cols+1, x1+2*i, "&&");

    mvwaddstr(win, y1+cols+1, x2, "&&");

    wrefresh(win);
}
[/code]

curses問題-輸入字符時光標不移動為什麼?

while(1) {

      int x=12, y=5;
      int i=0;
      int buff[12];
...
老兄啊,放在while裡面每次x,y不都是相同嗎?

curses問題-輸入字符時光標不移動為什麼?

是的,不好意思,我剛剛發現.



Copyright © 1999-2000 LSLNET.COM. All rights reserved. 藍森林網站 版權所有。 E-mail : webmaster@lslnet.com