FD_SET的C编程错误

时间:2011-11-06 17:43:17

标签: c linux compilation timeout select-function

我的代码存在问题,我无法找出问题是什么,因为我是新手来选择();
谁能告诉我这是什么问题?


run_fct.c: In function ‘run’:
run_fct.c:22: error: invalid type argument of ‘->’ (have ‘fd_set’)
cc1: warnings being treated as errors
run_fct.c:11: error: unused variable ‘timeout’
make: *** [run_fct.o] Error 1

FD_SET(0, fds);

void run(t_coord* piece, t_env* env, t_used_piece* rand_piece)
{
    char            arrows[2000];
    int             number;
    int             nread;
    int             ret;
    fd_set          fds;
    struct timeval  timeout;
    int             test;

    test = 0;
    (void)env;
    number = 0;
    set_keypress();
    init_pieces(piece);
    while (1)
    {
        FD_ZERO(&fds);
        FD_SET(0, fds);
        ret = select(1, &fds, 0, 0, 0);
        if (test == 0)
        {
            get_piece(rand_piece);
            number = rand_piece->piece;
            print_piece(env, piece, number);
        }
        if (ret > 0)
        {
            if (FD_ISSET(0, &fds))
            {
                nread = read(0, arrows, 3);
                if (arrows[0] == 27 && arrows[1] == '[' && arrows[2] == 'A')
                {
                    printf("A = UP\n");
                    piece[number].ay = piece[number].ay + 1;
                }
                else if (arrows[0] == 27 && arrows[1] == '[' && arrows[2] == 'B')
                {
                    piece[number].ay = piece[number].ay + 2;
                }
                else if (arrows[0] == 27 && arrows[1] == '[' && arrows[2] == 'C')
                {
                    piece[number].ax = piece[number].ax + 1;
                    piece[number].ay = piece[number].ay + 1;
                }
                else if (arrows[0] == 27 && arrows[1] == '[' && arrows[2] == 'D')
                {
                    piece[number].ax = piece[number].ax - 1;
                    piece[number].ay = piece[number].ay + 1;
                }
                else
                {
                    piece[number].ay = piece[number].ay + 1;
                }
            }
        }
        test = 1;
    }
    reset_keypress();
}

2 个答案:

答案 0 :(得分:1)

您忘记将fd_set作为指针传递。

答案 1 :(得分:1)

也许您的意思是FD_SET(0, &fds);(您在&之前忘记了fds)。

我希望您知道使用select有一些限制。 ppollpollpselect可能会更好。