给定的代码产生浮点异常,谁能告诉我这是由什么引起的?
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);
}
最佳答案
根据给定的代码,我想,它只能在这里,
pos->x = 2 + rand() % data.row;
pos->y = 2 + rand() % data.col;
确保data.row
和data.col
非零。否则,问题可能出在其他地方。
关于c - 浮点异常C代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7864252/