subscripted value is neither array nor pointer

This is a discussion on subscripted value is neither array nor pointer within the C Programming forums, part of the General Programming Boards category; part of my program involves printing a 2 dimensional character array, so i wrote: Code: for(i=0; i<rows; i++){ for(j=0; j<columns; ...

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    3

    subscripted value is neither array nor pointer

    part of my program involves printing a 2 dimensional character array, so i wrote:

    Code:
    for(i=0; i<rows; i++){
             for(j=0; j<columns; j++){
                      if (grid[i][j] == 'E')
                      printf("   ");
                      else
                      printf(" %c ", grid[i][j]);
             }    
             printf("\n");
    }
    so every 'E' is replaced with a blank space.
    but the compiler said "subscripted value is neither array nor pointer".
    can somebody help???

  2. #2
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    can you post the full code so we see how everything is declared.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    I would guess that grid isn't declared like you think it is. Post how you declared it, as nadroj suggested.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    Registered User
    Join Date
    Mar 2007
    Posts
    3

    here's how it's declared

    i'm not going to post the full code cause it's 250 lines.
    grid is declared like this

    Code:
    char grid[32][32];
    in the main function, and initialized using values from a file.
    it's passed to my display function like this

    Code:
    display(grid, rows, columns);
    the code i posted before is within the display function.

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by new_to_c View Post
    part of my program involves printing a 2 dimensional character array, so i wrote:

    Code:
    for(i=0; i<rows; i++){
             for(j=0; j<columns; j++){
                      if (grid[i][j] == 'E')
                         printf("   ");
                      else
                         printf(" %c ", grid[i][j]);
             }    
             printf("\n");
    }
    so every 'E' is replaced with a blank space.
    but the compiler said "subscripted value is neither array nor pointer".
    can somebody help???
    You mean every 'E' is replaced with a blank space on the print out, of course. There's nothing wrong with those for loops.

    Error is elsewhere in your code.

    Adak

  6. #6
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    and where is the function prototype?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  7. #7
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    Give us the whole function, starting from:

    void

    to

    }

    assuming it's void, that is

  8. #8
    Registered User
    Join Date
    Mar 2007
    Posts
    3
    Code:
    void display(grid, rows, columns){
    int i, j;
    
    /*simply to number the columns:*/
    
    for(i=1; i<=columns; i++)
             printf("%3d", i);
    
    printf("\n");
    
    for(i=0; i<rows; i++){
             for(j=0; j<columns; j++)
                      printf(" %c ", grid[i][j]);
             printf("\n");
    }
    
    /*score is a global variable*/
    
    printf("\n\n\nscore: %d", score);
    }

  9. #9
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,709
    Give your parameters appropriate types before you try to use your functions.
    That's why you get the error.
    For instance:
    Code:
    void DisplayGrid ( char grid[][32], unsigned int rows, unsigned int columns )
    {
      /* ... */
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. from 2D array to 1D array
    By cfdprogrammer in forum C Programming
    Replies: 17
    Last Post: 03-24-2009, 10:33 AM
  2. Replies: 9
    Last Post: 03-16-2009, 02:18 AM
  3. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 07:31 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21