【发布时间】:2013-02-14 21:59:37
【问题描述】:
我正在做一个小项目,我想知道为什么这段代码会导致我的程序崩溃。
PLAYER_FILE_PATH -- "player.txt"
sprite=yoshi.bmp
width=64
height=64
frames=8
alignment=1
animate=1
程序
FILE *pfile = fopen(PLAYER_FILE_PATH, "r");
if (!pfile)
{
debug_printf("could not open player file for reading!\n");
return;
}
fscanf(pfile, "sprite=%s\n\
width=%d\n\
height=%d\n\
frames=%d\n\
alignment=%d\n\
animate=%d",
player_entity.entity_sprite.imgloc,
&player_entity.entity_sprite.width,
&player_entity.entity_sprite.height,
&player_entity.entity_sprite.frames,
&player_entity.entity_sprite.oscdir,
&player_entity.entity_sprite.osc);
fclose(pfile);
【问题讨论】:
-
你能显示一个“player_entity”的定义吗?
-
确保
player_entity.entity_sprite.imgloc被正确分配(一个缓冲区的生命周期与player_entity的生命周期相关联,或者通过调用malloc动态分配)。 -
专业提示:Select Isn't Broken。 你正在使程序崩溃。