浮点异常C代码
给定的代码产生浮点异常,谁能告诉我这是由什么引起的?
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);
}
The given code produces a Floating point exception ,Can anyone tell me what this caused by?
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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据给定的代码,我想,只有在这里才可能,
确保
data.row
和data.col
非零。否则,问题可能出在其他地方。As per the given code,I suppose, Its only possible here,
make sure that
data.row
anddata.col
are non-zero. Or else, the problem might be somewhere else.