所以,我无法从我的文件中读取。
我想读这个文件;
1
0 0 0 0 0 0 0 0
0 0 0 2 0 0 0 0
0 0 0 2 0 0 0 0
0 0 0 2 1 0 0 0
0 0 1 2 2 0 0 0
0 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
第一个 1 是我的玩家,而数组是我的游戏板。
所以我正在尝试使用以下代码阅读所有这些内容:
void initialize_file(Game *game)
{
int i,j;
FILE *file = fopen("save.sav", "r");
if(file==NULL)
{
printf("Can't read file.... \n");
}
else
{
game->player=(fgetc(file)-'0');
printf("Player %d loaded\n",jeu->player);
fgetc(file); //jump the two lines after player
fgetc(file);
for(i=0;i<8;i++)
{
for(j=0;j<8;j++)
{
Game->game[i][j] = (fgetc(file)-'0');
printf("value : %d \n",Game->game[i][j]);
fgetc(file);
}
fgetc(file);
}
}
}
我的问题是我有时会在我的数组之外获得值,例如 -16 和 -38,它们分别引用 Space 和 LF。所以我的问题是:我怎样才能避免跑到这些 -16 和 -38 ?
非常感谢,对于任何英语错误,我深表歉意