给定代码会产生浮点异常,任何人都可以告诉我这是由什么造成的吗?
int play(t_env* env, t_pos* pos)
{
pid_t pid;
int ret;
t_data data;
int status;
pos->addx = 1;
pos->addy = 0;
pos->x = 2 + rand() % data.row;
pos->y = 2 + rand() % data.col;
pid = getpid();
ret = waitpid(WAIT_ANY, &status, WNOHANG);
if (ret == -1)
{
id_print_str("Error during waiting stat");
exit(1);
}
while (pos->x != data.row)
{
tputs(tgoto(env->cm, pos->x, pos->y), 1, id_put);
id_print_char('1');
sleep(1);
pos->x = pos->x + pos->addx;
pos->y = pos->y + pos->addy;
return (0);
}
答案 0 :(得分:1)
根据给定的代码,我想,它只能在这里,
pos->x = 2 + rand() % data.row;
pos->y = 2 + rand() % data.col;
确保data.row
和data.col
不为零。否则,问题可能在其他地方。