structures

This is a discussion on structures within the C++ Programming forums, part of the General Programming Boards category; Okay dudes back for yet another semester of mind bending programming. Anyhow dudes I totally forgot something from last semester. ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    78

    structures

    Okay dudes back for yet another semester of mind bending programming. Anyhow dudes I totally forgot something from last semester. I was just wondering if anyone out there could refresh my memory on how to build a structure with an array of entries.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    struct foo
    {
        int array[10];
    } bar[10], *baz;
    
    int x, y;
    
    /* since I don't know exactly what you are stuck on... */
    for( x = 0; x < 10; x++ )
        for( y = 0; y < 10; y++ )
            bar[x].array[y] = x * 10 + y;
    
    /* and of course, via pointers... */
    baz = bar;
    for( x = 0; x < 10; x++, baz++ )
        for( y = 0; y < 10; y++ )
            baz->array[y] = x * 10 + y;
    That looks about right...

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Another solution is STL vector container.

    Kuphryn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 08:39 AM
  2. Structures, passing array of structures to function
    By saahmed in forum C Programming
    Replies: 10
    Last Post: 04-06-2006, 12:06 AM
  3. Input output with structures
    By barim in forum C Programming
    Replies: 10
    Last Post: 04-27-2004, 09:00 PM
  4. pointers to arrays of structures
    By terryrmcgowan in forum C Programming
    Replies: 1
    Last Post: 06-25-2003, 10:04 AM
  5. Methods for Sorting Structures by Element...
    By Sebastiani in forum C Programming
    Replies: 9
    Last Post: 09-14-2001, 01:59 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21