initializing nested structure arrays

This is a discussion on initializing nested structure arrays within the C Programming forums, part of the General Programming Boards category; I'm working on a problem that uses a nested structure, and i have this portion of code that's giving me ...

  1. #1
    Advanced Novice linucksrox's Avatar
    Join Date
    Apr 2004
    Location
    Michigan
    Posts
    198

    initializing nested structure arrays

    I'm working on a problem that uses a nested structure, and i have this portion of code that's giving me a problem. I have NO idea what the heck is wrong with it...
    Code:
    struct person {
        char fname[50];
        char mname[50];
        char lname[50];
    };
    
    struct ssinfo {
        char ssnum[10];
        struct person name;
    };
    
    void printssinfo(struct ssinfo peoples);
    
    int main(void)
    {
        struct ssinfo people[5] = {
                       {"123456789"}, {"E", "D", "D"},
                       {"123456789"}, {"E", "D", "D"},
                       {"123456789"}, {"E", "D", "D"}, /* HERE */
                       {"123456789"}, {"E", "D", "D"},
                       {"123456789"}, {"E", "D", "D"}
        };
        ... print stuff then return 0;
    }
    right where it says "HERE" it gives me this error: [Warning] excess elements in array initializer
    when i set the people array to [10] instead of [5] it doesn't give me ANY errors but i know that's wrong... any ideas? what have I done wrong?

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    That's because it should be:
    Code:
    struct ssinfo people[5] =
    {
        { "now", { "e", "d", "d } }, /* first one ... */
        { "do", { "e", "d", "d } }, /* second one ... */
        { "you", { "e", "d", "d } }, /* third one ... */
        { "see", { "e", "d", "d } }, /* fourth one ... */
        { "?", { "e", "d", "d } } /* last one ... */
    };
    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Advanced Novice linucksrox's Avatar
    Join Date
    Apr 2004
    Location
    Michigan
    Posts
    198
    awesome thanks... i'm just not thinking tonight

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Segmentation faults when initializing large arrays
    By MathFan in forum C++ Programming
    Replies: 5
    Last Post: 07-14-2008, 05:24 AM
  2. initializing multi-dimensional arrays
    By cyberfish in forum C++ Programming
    Replies: 4
    Last Post: 10-31-2007, 08:15 PM
  3. help with structure arrays
    By mapunk in forum C Programming
    Replies: 8
    Last Post: 11-17-2005, 07:44 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. initializing arrays with letters
    By volk in forum C Programming
    Replies: 16
    Last Post: 01-28-2003, 06:28 PM

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