Thread: accesing struct members

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    57

    accesing struct members

    K i was wondering if i have a struct square with bool _1 ,_2, _3
    can i acces them like this

    Code:
    square box;
    for (int x=1;x>3;x++)
    {
            box.'_+x'=false;
    }
    Basically i am trying to safe some space instead of doing this

    Code:
    box._1=false;
    box._2=false;
    box._3=false;
    See what i am trying to do? Thanks i just got a lot of them 9 but if i have to do that everytime i need to acces them all it will take lot of code thanks and i am making sudoku solver thanks again.

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Use an array it looks like this.
    Code:
    struct myStruct
    {
        //creates 5 ints
        int vals[5];
    };
    
    int main()
    {
        myStruct ms;
        for(int i = 0; i < 5; i++){
            //Set each val to 1
            ms.vals[i] = 1;
        }
        return 0;
    }
    Woop?

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    57
    Yah but hmm this might work let me try this have anyone made sudoku solver and have anyhints?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  2. Replies: 16
    Last Post: 10-29-2006, 05:04 AM
  3. What's wrong with my search program?
    By sherwi in forum C Programming
    Replies: 5
    Last Post: 04-28-2006, 09:57 AM
  4. Function validation.
    By Fhl in forum C Programming
    Replies: 10
    Last Post: 02-22-2006, 08:18 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM