Thread: a simple struct problem...

  1. #1
    Registered User Finchie_88's Avatar
    Join Date
    Aug 2004
    Posts
    154

    Question a simple struct problem...

    Ive got a structure in my program, (look below), but I have a problem, in the stucture, what I want to do is to make a while loop that does something like this...
    Code:
    int x = 0;
    int y = 1;
    while(x < 9)
    {
    piece_green.py[1] = Position.X;
    piece_green.py[2] = Position.Y;
    x++;
    y++; // I want to cycle through the struct, but only the 'p's
    }
    stuct:-
    Code:
    struct piece_green
    {
    int p1;
    int p2;
    int p3; // This carries on up to eight
    }


  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Something to chew on...
    Code:
    struct piece_green
    {
       int p[8];
    };
    gg

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    Code:
    struct green_piece
    {
         int p[8];
    };
    int main()
    {
         green_piece gp;
         for(int i =0; i < 9; i++)
                      gp.p[i] = i;
         return 0;
      
    }
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Quote Originally Posted by misplaced
    Code:
    struct green_piece
    {
         int p[8];
    };
    
    ...
    
    for(int i =0; i < 9; i++)
    Typo?

    Code:
    for(int i =0; i < 8; i++)
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-21-2009, 12:37 AM
  2. Looking for a way to store listbox data
    By Welder in forum C Programming
    Replies: 20
    Last Post: 11-01-2007, 11:48 PM
  3. Replies: 16
    Last Post: 10-29-2006, 05:04 AM
  4. Struct Problem
    By Mr.Modem in forum C Programming
    Replies: 5
    Last Post: 08-13-2005, 03:19 PM
  5. moving ground terrain - problem accesing struct
    By nicky8211 in forum Game Programming
    Replies: 3
    Last Post: 11-10-2003, 11:08 AM