Thread: Want help using struct pointers

  1. #1
    Registered User
    Join Date
    May 2010

    Want help using struct pointers

    I want to be able to use pointers to manipulate a struct I have defined as opposed to returning a struct object from the method. While I am not horribly concerned about optimization at this stage, I used to know how to this this.

    Constants and typedef code, from header file:
    #define FIARROWS 6
    #define FIARCOLUMNS 7
    typedef enum {PLAYER1, PLAYER2, PLAYER3, PLAYER4, EMPTY} player;
    typedef struct
    	int COLUMNS;
    	int ROWS;
    	int locations[FIARCOLUMNS][FIARROWS];
    } FIARBoard;
    I understand the struct may seem unnecessary at this point, but it has a purpose that should evolve as the code does. The goal of the function I want help with is to set every location in the array to EMPTY.
    My code attempt.
    void FIARClearBoard (FIARBoard* board)
        for (int x=0; x<FIARCOLUMNS; x++)
            for (int y=0; y<FIARROWS; y++)
                board.locations[x][y] = EMPTY;
    This method produces the error "Request for member 'locations' in something not a structure or union".

    How should I approach this differently?
    Last edited by burkoJames; 05-13-2010 at 10:55 PM.

  2. #2
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    London, United Kingdom
    board is a pointer so use board->locations
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  3. #3
    Registered User
    Join Date
    May 2010
    Thanks! I haven't used C in a long time, but it works better then C++ when programming for both windows API and Cocoa.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help assignment due tomorrow
    By wildiv in forum C Programming
    Replies: 6
    Last Post: 01-27-2010, 08:38 PM
  2. Assignment HELP!!
    By cprogrammer22 in forum C Programming
    Replies: 35
    Last Post: 01-24-2009, 02:24 PM
  3. Function validation.
    By Fhl in forum C Programming
    Replies: 10
    Last Post: 02-22-2006, 08:18 AM
  4. Array of struct pointers - Losing my mind
    By drucillica in forum C Programming
    Replies: 5
    Last Post: 11-12-2005, 11:50 PM
  5. Pointers on pointers to pointers please...
    By Morgan in forum C Programming
    Replies: 2
    Last Post: 05-16-2003, 11:24 AM