How to initialize this array of structures of array of structures?












4















I have the following code, which is not working as expected. It compiles, but throws a lot of warnings and segfaults when executed:



#include <stdio.h>

enum output {
A,
B,
C,
D,
};

struct translation {
char *from;
enum output to;
};

struct dictionary {
struct translation *foo;
struct translation *bar;
};

enum language {
ONE,
ANOTHER,
};

struct dictionary languages = {
[ONE] = {
.foo = {
{"LF", A},
{"LLF", C},
{"RRF", D},
},
.bar = {
{"L", B},
},
},
[ANOTHER] = {
.foo = {
{"FF", B},
{"RRF", D},
},
.bar = {
{"LF", B},
{"R", C},
{"RR", D},
},
},
};

int main(void)
{
printf("%sn", languages[ONE].foo[0].from);
return 0;
}


I am probably initializing languages the wrong way.




  • I would like to have that languages array in which I can access different dictionaries by language: languages[ONE]

  • I would like to access then different translation tables with the dictionary field: languages[ONE].foo

  • All translation tables accessed with a language+field pair may have different array lengths, as shown in the code example


Is that even possible? What am I doing wrong?



When compiling with gcc I get this (cropped) output:



asdf.c:27:17: warning: braces around scalar initializer
.foo = {
^
asdf.c:27:17: note: (near initialization for ‘languages[0].foo’)
asdf.c:28:25: warning: braces around scalar initializer
{"LF", A},
^
asdf.c:28:25: note: (near initialization for ‘languages[0].foo’)
asdf.c:28:26: warning: initialization of ‘struct translation *’ from incompatible pointer type ‘char *’ [-Wincompatible-pointer-types]

[...]


The same warnings/notes repeat for multiple parts of the code.










share|improve this question























  • @FiddlingBits Actually, that could be a workaround! :-) I tried with (no size) but that was illegal. You can post that as an answer if you want. Although I will wait before accepting to see if there is a way of making this work without having to specify a dictionary table size "big enough" to hold all translations.

    – Peque
    Nov 19 '18 at 21:35
















4















I have the following code, which is not working as expected. It compiles, but throws a lot of warnings and segfaults when executed:



#include <stdio.h>

enum output {
A,
B,
C,
D,
};

struct translation {
char *from;
enum output to;
};

struct dictionary {
struct translation *foo;
struct translation *bar;
};

enum language {
ONE,
ANOTHER,
};

struct dictionary languages = {
[ONE] = {
.foo = {
{"LF", A},
{"LLF", C},
{"RRF", D},
},
.bar = {
{"L", B},
},
},
[ANOTHER] = {
.foo = {
{"FF", B},
{"RRF", D},
},
.bar = {
{"LF", B},
{"R", C},
{"RR", D},
},
},
};

int main(void)
{
printf("%sn", languages[ONE].foo[0].from);
return 0;
}


I am probably initializing languages the wrong way.




  • I would like to have that languages array in which I can access different dictionaries by language: languages[ONE]

  • I would like to access then different translation tables with the dictionary field: languages[ONE].foo

  • All translation tables accessed with a language+field pair may have different array lengths, as shown in the code example


Is that even possible? What am I doing wrong?



When compiling with gcc I get this (cropped) output:



asdf.c:27:17: warning: braces around scalar initializer
.foo = {
^
asdf.c:27:17: note: (near initialization for ‘languages[0].foo’)
asdf.c:28:25: warning: braces around scalar initializer
{"LF", A},
^
asdf.c:28:25: note: (near initialization for ‘languages[0].foo’)
asdf.c:28:26: warning: initialization of ‘struct translation *’ from incompatible pointer type ‘char *’ [-Wincompatible-pointer-types]

[...]


The same warnings/notes repeat for multiple parts of the code.










share|improve this question























  • @FiddlingBits Actually, that could be a workaround! :-) I tried with (no size) but that was illegal. You can post that as an answer if you want. Although I will wait before accepting to see if there is a way of making this work without having to specify a dictionary table size "big enough" to hold all translations.

    – Peque
    Nov 19 '18 at 21:35














4












4








4


1






I have the following code, which is not working as expected. It compiles, but throws a lot of warnings and segfaults when executed:



#include <stdio.h>

enum output {
A,
B,
C,
D,
};

struct translation {
char *from;
enum output to;
};

struct dictionary {
struct translation *foo;
struct translation *bar;
};

enum language {
ONE,
ANOTHER,
};

struct dictionary languages = {
[ONE] = {
.foo = {
{"LF", A},
{"LLF", C},
{"RRF", D},
},
.bar = {
{"L", B},
},
},
[ANOTHER] = {
.foo = {
{"FF", B},
{"RRF", D},
},
.bar = {
{"LF", B},
{"R", C},
{"RR", D},
},
},
};

int main(void)
{
printf("%sn", languages[ONE].foo[0].from);
return 0;
}


I am probably initializing languages the wrong way.




  • I would like to have that languages array in which I can access different dictionaries by language: languages[ONE]

  • I would like to access then different translation tables with the dictionary field: languages[ONE].foo

  • All translation tables accessed with a language+field pair may have different array lengths, as shown in the code example


Is that even possible? What am I doing wrong?



When compiling with gcc I get this (cropped) output:



asdf.c:27:17: warning: braces around scalar initializer
.foo = {
^
asdf.c:27:17: note: (near initialization for ‘languages[0].foo’)
asdf.c:28:25: warning: braces around scalar initializer
{"LF", A},
^
asdf.c:28:25: note: (near initialization for ‘languages[0].foo’)
asdf.c:28:26: warning: initialization of ‘struct translation *’ from incompatible pointer type ‘char *’ [-Wincompatible-pointer-types]

[...]


The same warnings/notes repeat for multiple parts of the code.










share|improve this question














I have the following code, which is not working as expected. It compiles, but throws a lot of warnings and segfaults when executed:



#include <stdio.h>

enum output {
A,
B,
C,
D,
};

struct translation {
char *from;
enum output to;
};

struct dictionary {
struct translation *foo;
struct translation *bar;
};

enum language {
ONE,
ANOTHER,
};

struct dictionary languages = {
[ONE] = {
.foo = {
{"LF", A},
{"LLF", C},
{"RRF", D},
},
.bar = {
{"L", B},
},
},
[ANOTHER] = {
.foo = {
{"FF", B},
{"RRF", D},
},
.bar = {
{"LF", B},
{"R", C},
{"RR", D},
},
},
};

int main(void)
{
printf("%sn", languages[ONE].foo[0].from);
return 0;
}


I am probably initializing languages the wrong way.




  • I would like to have that languages array in which I can access different dictionaries by language: languages[ONE]

  • I would like to access then different translation tables with the dictionary field: languages[ONE].foo

  • All translation tables accessed with a language+field pair may have different array lengths, as shown in the code example


Is that even possible? What am I doing wrong?



When compiling with gcc I get this (cropped) output:



asdf.c:27:17: warning: braces around scalar initializer
.foo = {
^
asdf.c:27:17: note: (near initialization for ‘languages[0].foo’)
asdf.c:28:25: warning: braces around scalar initializer
{"LF", A},
^
asdf.c:28:25: note: (near initialization for ‘languages[0].foo’)
asdf.c:28:26: warning: initialization of ‘struct translation *’ from incompatible pointer type ‘char *’ [-Wincompatible-pointer-types]

[...]


The same warnings/notes repeat for multiple parts of the code.







c arrays struct initialization






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 '18 at 21:24









PequePeque

5,70733362




5,70733362













  • @FiddlingBits Actually, that could be a workaround! :-) I tried with (no size) but that was illegal. You can post that as an answer if you want. Although I will wait before accepting to see if there is a way of making this work without having to specify a dictionary table size "big enough" to hold all translations.

    – Peque
    Nov 19 '18 at 21:35



















  • @FiddlingBits Actually, that could be a workaround! :-) I tried with (no size) but that was illegal. You can post that as an answer if you want. Although I will wait before accepting to see if there is a way of making this work without having to specify a dictionary table size "big enough" to hold all translations.

    – Peque
    Nov 19 '18 at 21:35

















@FiddlingBits Actually, that could be a workaround! :-) I tried with (no size) but that was illegal. You can post that as an answer if you want. Although I will wait before accepting to see if there is a way of making this work without having to specify a dictionary table size "big enough" to hold all translations.

– Peque
Nov 19 '18 at 21:35





@FiddlingBits Actually, that could be a workaround! :-) I tried with (no size) but that was illegal. You can post that as an answer if you want. Although I will wait before accepting to see if there is a way of making this work without having to specify a dictionary table size "big enough" to hold all translations.

– Peque
Nov 19 '18 at 21:35












2 Answers
2






active

oldest

votes


















3














Here are two things you can do:




  1. Allocate memory for struct translation *foo; and struct translation *bar; (you can also use malloc to dynamically allocate memory). For example:



struct dictionary
{
struct translation foo[10];
struct translation bar[10];
};



  1. Use a compound literal in your definition:



struct dictionary languages = {
[ONE] = {
.foo = (struct translation ){
{"LF", A},
{"LLF", C},
{"RRF", D},
},
.bar = (struct translation ){
{"L", B},
},
},
[ANOTHER] = {
.foo = (struct translation ){
{"FF", B},
{"RRF", D},
},
.bar = (struct translation ){
{"LF", B},
{"R", C},
{"RR", D},
},
},
};


Note



As mentioned by @M.M, adding the qualifier const before struct dictionary is a good idea if its values won't change during runtime.






share|improve this answer





















  • 1





    Love the latter <3. I am learning a lot of C with this project. :-D

    – Peque
    Nov 19 '18 at 21:42











  • Would appreciate knowing why I was downvoted.

    – Fiddling Bits
    Nov 19 '18 at 21:42













  • something like struct translation foo[10]; (leaving some of them uninitialized) is a very poor idea while compound literals are feature of C99 language

    – VTT
    Nov 19 '18 at 21:46













  • @VTT Sure. I mentioned it as an option, not a recommendation.

    – Fiddling Bits
    Nov 19 '18 at 21:47








  • 1





    @VTT not necessarily; in some systems memory is cheap and other concerns such as code clarity, portability, ease of development, ease of runtime access etc. may have a higher priority

    – M.M
    Nov 19 '18 at 22:03



















1














Just initialize each array separately:



#include <stdio.h>

enum output
{
a
, b
, c
, d
};

struct translation
{
char const * from;
enum output to;
};

struct dictionary
{
struct translation * foo;
struct translation * bar;
};

enum language
{
one
, another
, languages_count
};

struct translation one_language_foo_translations =
{
{"LF" , a}
, {"LLF", c}
, {"RRF", d}
};

struct translation one_language_bar_translations =
{
{"L", b}
};

struct translation another_language_foo_translations =
{
{"FF" , b}
, {"RRF", d}
};

struct translation another_language_bar_translations =
{
{"LF", b}
, {"R" , c}
, {"RR", d}
};

struct dictionary languages[languages_count] =
{
{one_language_foo_translations, one_language_bar_translations}
, {another_language_foo_translations, another_language_bar_translations}
};

int main(void)
{
printf("%sn", languages[one].foo[0].from);
return 0;
}


online compiler






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53382857%2fhow-to-initialize-this-array-of-structures-of-array-of-structures%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    Here are two things you can do:




    1. Allocate memory for struct translation *foo; and struct translation *bar; (you can also use malloc to dynamically allocate memory). For example:



    struct dictionary
    {
    struct translation foo[10];
    struct translation bar[10];
    };



    1. Use a compound literal in your definition:



    struct dictionary languages = {
    [ONE] = {
    .foo = (struct translation ){
    {"LF", A},
    {"LLF", C},
    {"RRF", D},
    },
    .bar = (struct translation ){
    {"L", B},
    },
    },
    [ANOTHER] = {
    .foo = (struct translation ){
    {"FF", B},
    {"RRF", D},
    },
    .bar = (struct translation ){
    {"LF", B},
    {"R", C},
    {"RR", D},
    },
    },
    };


    Note



    As mentioned by @M.M, adding the qualifier const before struct dictionary is a good idea if its values won't change during runtime.






    share|improve this answer





















    • 1





      Love the latter <3. I am learning a lot of C with this project. :-D

      – Peque
      Nov 19 '18 at 21:42











    • Would appreciate knowing why I was downvoted.

      – Fiddling Bits
      Nov 19 '18 at 21:42













    • something like struct translation foo[10]; (leaving some of them uninitialized) is a very poor idea while compound literals are feature of C99 language

      – VTT
      Nov 19 '18 at 21:46













    • @VTT Sure. I mentioned it as an option, not a recommendation.

      – Fiddling Bits
      Nov 19 '18 at 21:47








    • 1





      @VTT not necessarily; in some systems memory is cheap and other concerns such as code clarity, portability, ease of development, ease of runtime access etc. may have a higher priority

      – M.M
      Nov 19 '18 at 22:03
















    3














    Here are two things you can do:




    1. Allocate memory for struct translation *foo; and struct translation *bar; (you can also use malloc to dynamically allocate memory). For example:



    struct dictionary
    {
    struct translation foo[10];
    struct translation bar[10];
    };



    1. Use a compound literal in your definition:



    struct dictionary languages = {
    [ONE] = {
    .foo = (struct translation ){
    {"LF", A},
    {"LLF", C},
    {"RRF", D},
    },
    .bar = (struct translation ){
    {"L", B},
    },
    },
    [ANOTHER] = {
    .foo = (struct translation ){
    {"FF", B},
    {"RRF", D},
    },
    .bar = (struct translation ){
    {"LF", B},
    {"R", C},
    {"RR", D},
    },
    },
    };


    Note



    As mentioned by @M.M, adding the qualifier const before struct dictionary is a good idea if its values won't change during runtime.






    share|improve this answer





















    • 1





      Love the latter <3. I am learning a lot of C with this project. :-D

      – Peque
      Nov 19 '18 at 21:42











    • Would appreciate knowing why I was downvoted.

      – Fiddling Bits
      Nov 19 '18 at 21:42













    • something like struct translation foo[10]; (leaving some of them uninitialized) is a very poor idea while compound literals are feature of C99 language

      – VTT
      Nov 19 '18 at 21:46













    • @VTT Sure. I mentioned it as an option, not a recommendation.

      – Fiddling Bits
      Nov 19 '18 at 21:47








    • 1





      @VTT not necessarily; in some systems memory is cheap and other concerns such as code clarity, portability, ease of development, ease of runtime access etc. may have a higher priority

      – M.M
      Nov 19 '18 at 22:03














    3












    3








    3







    Here are two things you can do:




    1. Allocate memory for struct translation *foo; and struct translation *bar; (you can also use malloc to dynamically allocate memory). For example:



    struct dictionary
    {
    struct translation foo[10];
    struct translation bar[10];
    };



    1. Use a compound literal in your definition:



    struct dictionary languages = {
    [ONE] = {
    .foo = (struct translation ){
    {"LF", A},
    {"LLF", C},
    {"RRF", D},
    },
    .bar = (struct translation ){
    {"L", B},
    },
    },
    [ANOTHER] = {
    .foo = (struct translation ){
    {"FF", B},
    {"RRF", D},
    },
    .bar = (struct translation ){
    {"LF", B},
    {"R", C},
    {"RR", D},
    },
    },
    };


    Note



    As mentioned by @M.M, adding the qualifier const before struct dictionary is a good idea if its values won't change during runtime.






    share|improve this answer















    Here are two things you can do:




    1. Allocate memory for struct translation *foo; and struct translation *bar; (you can also use malloc to dynamically allocate memory). For example:



    struct dictionary
    {
    struct translation foo[10];
    struct translation bar[10];
    };



    1. Use a compound literal in your definition:



    struct dictionary languages = {
    [ONE] = {
    .foo = (struct translation ){
    {"LF", A},
    {"LLF", C},
    {"RRF", D},
    },
    .bar = (struct translation ){
    {"L", B},
    },
    },
    [ANOTHER] = {
    .foo = (struct translation ){
    {"FF", B},
    {"RRF", D},
    },
    .bar = (struct translation ){
    {"LF", B},
    {"R", C},
    {"RR", D},
    },
    },
    };


    Note



    As mentioned by @M.M, adding the qualifier const before struct dictionary is a good idea if its values won't change during runtime.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 19 '18 at 22:05

























    answered Nov 19 '18 at 21:37









    Fiddling BitsFiddling Bits

    7,10821938




    7,10821938








    • 1





      Love the latter <3. I am learning a lot of C with this project. :-D

      – Peque
      Nov 19 '18 at 21:42











    • Would appreciate knowing why I was downvoted.

      – Fiddling Bits
      Nov 19 '18 at 21:42













    • something like struct translation foo[10]; (leaving some of them uninitialized) is a very poor idea while compound literals are feature of C99 language

      – VTT
      Nov 19 '18 at 21:46













    • @VTT Sure. I mentioned it as an option, not a recommendation.

      – Fiddling Bits
      Nov 19 '18 at 21:47








    • 1





      @VTT not necessarily; in some systems memory is cheap and other concerns such as code clarity, portability, ease of development, ease of runtime access etc. may have a higher priority

      – M.M
      Nov 19 '18 at 22:03














    • 1





      Love the latter <3. I am learning a lot of C with this project. :-D

      – Peque
      Nov 19 '18 at 21:42











    • Would appreciate knowing why I was downvoted.

      – Fiddling Bits
      Nov 19 '18 at 21:42













    • something like struct translation foo[10]; (leaving some of them uninitialized) is a very poor idea while compound literals are feature of C99 language

      – VTT
      Nov 19 '18 at 21:46













    • @VTT Sure. I mentioned it as an option, not a recommendation.

      – Fiddling Bits
      Nov 19 '18 at 21:47








    • 1





      @VTT not necessarily; in some systems memory is cheap and other concerns such as code clarity, portability, ease of development, ease of runtime access etc. may have a higher priority

      – M.M
      Nov 19 '18 at 22:03








    1




    1





    Love the latter <3. I am learning a lot of C with this project. :-D

    – Peque
    Nov 19 '18 at 21:42





    Love the latter <3. I am learning a lot of C with this project. :-D

    – Peque
    Nov 19 '18 at 21:42













    Would appreciate knowing why I was downvoted.

    – Fiddling Bits
    Nov 19 '18 at 21:42







    Would appreciate knowing why I was downvoted.

    – Fiddling Bits
    Nov 19 '18 at 21:42















    something like struct translation foo[10]; (leaving some of them uninitialized) is a very poor idea while compound literals are feature of C99 language

    – VTT
    Nov 19 '18 at 21:46







    something like struct translation foo[10]; (leaving some of them uninitialized) is a very poor idea while compound literals are feature of C99 language

    – VTT
    Nov 19 '18 at 21:46















    @VTT Sure. I mentioned it as an option, not a recommendation.

    – Fiddling Bits
    Nov 19 '18 at 21:47







    @VTT Sure. I mentioned it as an option, not a recommendation.

    – Fiddling Bits
    Nov 19 '18 at 21:47






    1




    1





    @VTT not necessarily; in some systems memory is cheap and other concerns such as code clarity, portability, ease of development, ease of runtime access etc. may have a higher priority

    – M.M
    Nov 19 '18 at 22:03





    @VTT not necessarily; in some systems memory is cheap and other concerns such as code clarity, portability, ease of development, ease of runtime access etc. may have a higher priority

    – M.M
    Nov 19 '18 at 22:03













    1














    Just initialize each array separately:



    #include <stdio.h>

    enum output
    {
    a
    , b
    , c
    , d
    };

    struct translation
    {
    char const * from;
    enum output to;
    };

    struct dictionary
    {
    struct translation * foo;
    struct translation * bar;
    };

    enum language
    {
    one
    , another
    , languages_count
    };

    struct translation one_language_foo_translations =
    {
    {"LF" , a}
    , {"LLF", c}
    , {"RRF", d}
    };

    struct translation one_language_bar_translations =
    {
    {"L", b}
    };

    struct translation another_language_foo_translations =
    {
    {"FF" , b}
    , {"RRF", d}
    };

    struct translation another_language_bar_translations =
    {
    {"LF", b}
    , {"R" , c}
    , {"RR", d}
    };

    struct dictionary languages[languages_count] =
    {
    {one_language_foo_translations, one_language_bar_translations}
    , {another_language_foo_translations, another_language_bar_translations}
    };

    int main(void)
    {
    printf("%sn", languages[one].foo[0].from);
    return 0;
    }


    online compiler






    share|improve this answer




























      1














      Just initialize each array separately:



      #include <stdio.h>

      enum output
      {
      a
      , b
      , c
      , d
      };

      struct translation
      {
      char const * from;
      enum output to;
      };

      struct dictionary
      {
      struct translation * foo;
      struct translation * bar;
      };

      enum language
      {
      one
      , another
      , languages_count
      };

      struct translation one_language_foo_translations =
      {
      {"LF" , a}
      , {"LLF", c}
      , {"RRF", d}
      };

      struct translation one_language_bar_translations =
      {
      {"L", b}
      };

      struct translation another_language_foo_translations =
      {
      {"FF" , b}
      , {"RRF", d}
      };

      struct translation another_language_bar_translations =
      {
      {"LF", b}
      , {"R" , c}
      , {"RR", d}
      };

      struct dictionary languages[languages_count] =
      {
      {one_language_foo_translations, one_language_bar_translations}
      , {another_language_foo_translations, another_language_bar_translations}
      };

      int main(void)
      {
      printf("%sn", languages[one].foo[0].from);
      return 0;
      }


      online compiler






      share|improve this answer


























        1












        1








        1







        Just initialize each array separately:



        #include <stdio.h>

        enum output
        {
        a
        , b
        , c
        , d
        };

        struct translation
        {
        char const * from;
        enum output to;
        };

        struct dictionary
        {
        struct translation * foo;
        struct translation * bar;
        };

        enum language
        {
        one
        , another
        , languages_count
        };

        struct translation one_language_foo_translations =
        {
        {"LF" , a}
        , {"LLF", c}
        , {"RRF", d}
        };

        struct translation one_language_bar_translations =
        {
        {"L", b}
        };

        struct translation another_language_foo_translations =
        {
        {"FF" , b}
        , {"RRF", d}
        };

        struct translation another_language_bar_translations =
        {
        {"LF", b}
        , {"R" , c}
        , {"RR", d}
        };

        struct dictionary languages[languages_count] =
        {
        {one_language_foo_translations, one_language_bar_translations}
        , {another_language_foo_translations, another_language_bar_translations}
        };

        int main(void)
        {
        printf("%sn", languages[one].foo[0].from);
        return 0;
        }


        online compiler






        share|improve this answer













        Just initialize each array separately:



        #include <stdio.h>

        enum output
        {
        a
        , b
        , c
        , d
        };

        struct translation
        {
        char const * from;
        enum output to;
        };

        struct dictionary
        {
        struct translation * foo;
        struct translation * bar;
        };

        enum language
        {
        one
        , another
        , languages_count
        };

        struct translation one_language_foo_translations =
        {
        {"LF" , a}
        , {"LLF", c}
        , {"RRF", d}
        };

        struct translation one_language_bar_translations =
        {
        {"L", b}
        };

        struct translation another_language_foo_translations =
        {
        {"FF" , b}
        , {"RRF", d}
        };

        struct translation another_language_bar_translations =
        {
        {"LF", b}
        , {"R" , c}
        , {"RR", d}
        };

        struct dictionary languages[languages_count] =
        {
        {one_language_foo_translations, one_language_bar_translations}
        , {another_language_foo_translations, another_language_bar_translations}
        };

        int main(void)
        {
        printf("%sn", languages[one].foo[0].from);
        return 0;
        }


        online compiler







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 '18 at 21:41









        VTTVTT

        24k42345




        24k42345






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53382857%2fhow-to-initialize-this-array-of-structures-of-array-of-structures%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith