Thread: pointers and structures

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    6

    Post pointers and structures

    /*fill a m x n grid with 0 or 1 */
    I'm trying to return a pointer to the cell on the grid but I'm not getting the correct output..please help me figure out what I'm doing wrong.
    Code:
    typedef enum
    {
        a,
        b
    } cell_alpha;
    Code:
    typedef struct
    {
        int rows;
        int columns;
        /* Pointer to the beginning of the grid cell data where the cells are in a row-major layout */
        cell_alpha * cells;
    } grid;
    need help with the following code:

    Code:
    cell_alpha * abc_cell(grid * present_grid, int row, int column)
    {
      return &cell_alpha *(row*(grid->rows)+column); /*! Return a pointer to the corresponding cell on the grid. */
    }
    Last edited by Jumgle; 04-16-2011 at 08:57 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Structures, and pointers to structures
    By iloveitaly in forum C Programming
    Replies: 4
    Last Post: 03-30-2005, 06:31 PM
  2. structures with pointers to structures
    By kzar in forum C Programming
    Replies: 3
    Last Post: 11-20-2004, 09:32 AM
  3. Pointers to Classes || pointers to structures
    By C++Child in forum C++ Programming
    Replies: 24
    Last Post: 07-30-2004, 06:14 PM
  4. pointers and structures
    By coo_pal in forum C Programming
    Replies: 1
    Last Post: 07-23-2003, 04:45 AM
  5. Replies: 5
    Last Post: 04-11-2002, 11:29 AM