2011-09-15 41 views
1

我得到的错误C编程:下标值既不是数组,也不指针

下标值既不是数组,也不指针

,当我尝试编译我的程序。我知道这与变量没有被声明有关,但我检查了一切,并且它似乎被声明了。

static char getValue(LOCATION l) 
{ 
    /*return carpark[l.col][l.row]; // Assumes that location is valid. Safe code is 
     below: 
    */ 


    if (isValidLocation(l)) { 
     return carpark[l.col][l.row]; <<<<<<<< this line 
     }  // returns char if valid (safe) 
    else { 
     return '.'; 
    } 

对应于这部分代码在头

typedef struct 
{ 
    /* Rectangular grid of characters representing the position of 
     all cars in the game. Each car appears precisely once in 
     the carpark */ 
    char grid[MAXCARPARKSIZE][MAXCARPARKSIZE]; 
    /* The number of rows used in carpark */ 
    int nRows; 
    /* The number of columns used in carpark */ 
    int nCols; 
    /* The location of the exit */ 
    LOCATION exit; 
} CARPARK; 

停车场被宣布在主PROG有:

CARPARK carpark. 

感谢您的帮助。

+0

你什么错误?请在您的问题中粘贴其确切的文字。 – Chriszuma

回答

7

carpark不是一个数组,所以你可能想是这样的:

return carpark.grid[l.col][l.row]; 
0

错误消息告诉您确切问题是什么。变量carpark既不是数组也不是指针,所以不能将[]运算符应用于它。

carpark.grid,然而,一个数组,所以你可以写

return carpark.grid[l.col][l.row]; 
相关问题