gpt4 book ai didi

FD_SET 的 C 编程错误

转载 作者:太空宇宙 更新时间:2023-11-04 09:53:46 25 4
gpt4 key购买 nike

我的代码有问题,我无法找出问题所在,因为我是 select() 的新手;
谁能告诉我问题出在哪里?


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();
}

最佳答案

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

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

关于FD_SET 的 C 编程错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8028969/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com