1

I get the error

subscripted value is neither array nor pointer

when I try to compile my program. I understand it has something to do with the variable not being declared but I checked everything and it seemed to be declared.

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 '.';
    }

Which corresponds to this part of the code in the header

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;

Carpark was declared in the main prog with:

CARPARK carpark. 

Thanks for the help.

1
  • What error do you get? Please paste its exact text in your question. Commented Sep 15, 2011 at 15:45

2 Answers 2

7

carpark is not an array so you probably want something like:

return carpark.grid[l.col][l.row];
Sign up to request clarification or add additional context in comments.

Comments

0

The error message is telling you exactly what the problem is. The variable carpark is neither an array nor a pointer, so you cannot apply the [] operator to it.

carpark.grid, however, is an array, so you could write

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.