Thread: Elements of an array in a struct?

  1. #1
    Registered User Ion Blade's Avatar
    Join Date
    May 2002
    Posts
    35

    Question Elements of an array in a struct?

    I have no idea if this is explained in a tutorial, but is it possible to make each element of an array part of a struct?

    Like:

    Code:
    char myChar [10];
    
    myChar [6] = 'A';
    myChar [6].isChanged = TRUE;

  2. #2
    Seeking motivation... endo's Avatar
    Join Date
    May 2002
    Posts
    537
    Not sure what you mean, any chance of a better explanation?
    Couldn't think of anything interesting, cool or funny - sorry.

  3. #3
    Registered User Ion Blade's Avatar
    Join Date
    May 2002
    Posts
    35
    It's hard for me to explain it... i'll try my best


    In my connect four game, i have a char (defined char board [8] [7]) to keep all the values of the board.

    Each space is either equal to O for empty, or X or Q for player pieces.

    So when i check if someone has won, i simply check if the current piece equals this player's piece, and then piece above also equals this player's piece, and so on...but i want to make a 2 on 2 version where you can only win if the piece the program is checking is part of your own team.

    So...if (board [blah] [blah] == 'X' & board [blah] [blah-1].team == board [blah] [blah].team) Win();
    is similar to what i want to do.
    "Im going to have peaceful dreams of brackets and semicolons strapped on crucifixes, screaming for mercy" - Someone who doesn't like programming.

  4. #4
    Registered User
    Join Date
    May 2002
    Posts
    17
    oh yes.. each member of an array can be pretty much anything you want, like a struct a class, another array (which is what 2 dimentional arrays are)

    try this:
    Code:
    struct Slot
    {
    int piece;
    int team;
    };
    
    struct Slot board[8][7];

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. populate an array struct
    By flipguy_ph in forum C Programming
    Replies: 10
    Last Post: 04-17-2009, 04:07 PM
  2. Replies: 1
    Last Post: 12-03-2008, 03:10 AM
  3. Global Variables
    By Taka in forum C Programming
    Replies: 34
    Last Post: 11-02-2007, 03:25 AM
  4. Writing an array of struct to file
    By stellastarr in forum C Programming
    Replies: 10
    Last Post: 03-25-2006, 06:59 PM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM