Thread: Initialisation query

  1. #1
    The Earth is not flat. Clyde's Avatar
    Join Date
    Mar 2002
    Posts
    1,403

    Initialisation query

    can you initialise an array of structs, with values when the structure contains a further array?

    for example

    I have a structure:

    Code:
    typedef struct PATTERNS
    		{
    		int pattern[10];
    		int	num_instructions;
    		} PAT, *PAT_PTR;
    and then i have an array of said structure and i want to initialise the whole bunch with values.

    I thought i could go some thing like:

    Code:
    PAT patternx[2] = {{5, 94, 8, 94, 3, 30, 4, 60, 3, 30}, 5, {5, 94, 8, 94, 3, 30, 4, 60, 3, 30}, 5};
    but the compiler complained.

    Any suggestions?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Just needs some more {}

    Code:
    PAT patternx[2] = {
        {
            { 5, 94, 8, 94, 3, 30, 4, 60, 3, 30 },
            5
        },
        {
            { 5, 94, 8, 94, 3, 30, 4, 60, 3, 30 },
            5
        },
    };

  3. #3
    The Earth is not flat. Clyde's Avatar
    Join Date
    Mar 2002
    Posts
    1,403
    I managed to get it to word by going the opposite way (though no doubt your way works too), i removed all the brackets except the first two, and it sprung to life

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple query language
    By afflictedd2 in forum C++ Programming
    Replies: 3
    Last Post: 12-04-2008, 05:29 PM
  2. query problem
    By arian in forum C# Programming
    Replies: 1
    Last Post: 08-18-2008, 01:49 PM
  3. DNS Query
    By Simpsonia in forum Networking/Device Communication
    Replies: 1
    Last Post: 04-24-2006, 12:42 AM
  4. dns query
    By bulldog in forum C Programming
    Replies: 6
    Last Post: 02-24-2004, 10:44 AM
  5. WBEM Query too slow
    By Unregistered in forum Windows Programming
    Replies: 0
    Last Post: 10-08-2001, 05:28 PM