0

嘿,伙计们,这不应该那么难,但为什么

            fscanf(fp, "%d", Map.tile[x][y]);

tile 部分说 Field 'tile' could not be resolved 抱歉遇到初学者问题,但我猜这应该是 char 到 int 转换的问题。我将如何解决这个问题?谢谢,waco001

void MapManager::loadMap(char *name){
    int x, y;
    FILE *fp;

    fp = fopen(name, "rb");
    const int MAX_MAP_Y = 32;
    const int MAX_MAP_X = 32;
    typedef struct Map
    {
        int tile[MAX_MAP_Y][MAX_MAP_X];
        char xs;
    } Map;
    /* If we can't open the map then exit */

    if (fp == NULL)
    {
        printf("Failed to open map %s\n", name);

        exit(1);
    }

    /* Read the data from the file into the map */

    for (y=0;y<MAX_MAP_Y;y++)
    {
        for (x=0;x<MAX_MAP_X;x++)
        {
            fscanf(fp, "%d", Map.tile[x][y]);
        }
    }

    /* Close the file afterwards */

    fclose(fp);
}
4

1 回答 1

2

Map是一种类型,但你需要一个对象。例如,您可以使用

Map map;
// ...
if (fscanf(fp, "%d", map.tile[x][y]) != 1) {
    fprintf(stderr, "ERROR: failed to read map.tile[%d][%d]\n", x, y);
}
于 2013-10-28T23:35:58.267 回答