Answers for "nested structures in c"

C
1

how to put a struct in another struct C

struct B {  // <-- declare before
  int number;
};
struct A {
 int data;
 B b; // <--- declare data member of `B`
 };
Posted by: Guest on May-08-2020
0

how we can strore a nested structure values in arrays

typedef struct {

    char ChannelNo[3];              //"P1"
    unsigned int ChannelPin;        //23
    char State;                     //'o'
}test;

typedef struct {

    test One[3];
    test two[3];
    test three[3];
    test four[3];
    test five;
    test six[3];

}matrix;

matrix x[] =
    {
    // [0]
        {
            .One = {
                     {.ChannelNo = "P4", .ChannelPin = 23, .State = 'o'},
                     {.ChannelNo = "P1", .ChannelPin = 98, .State = 'o'},
                     {.ChannelNo = "P0", .ChannelPin = 23, .State = 'o'},
            },
            .two = {
                    {.ChannelNo = "P5", .ChannelPin = 79, .State = 'd'},
                    {.ChannelNo = "P4", .ChannelPin = 79, .State = 'e'},
                    {.ChannelNo = "P5", .ChannelPin = 79, .State = 'r'},
            },
            // ......
            .five = {.ChannelNo = "P5", .ChannelPin = 79, .State = 'r'},
        },
    // [1]
        {
            .One = {
                     {.ChannelNo = "P4", .ChannelPin = 23, .State = 'o'},
                     {.ChannelNo = "P1", .ChannelPin = 98, .State = 'o'},
                     {.ChannelNo = "P0", .ChannelPin = 23, .State = 'o'},
            },
            .two = {
                    {.ChannelNo = "P5", .ChannelPin = 79, .State = 'd'},
                    {.ChannelNo = "P4", .ChannelPin = 79, .State = 'e'},
                    {.ChannelNo = "P5", .ChannelPin = 79, .State = 'r'},
            },
            // ......
            .five = {.ChannelNo = "P5", .ChannelPin = 79, .State = 'r'},
        },
    // ......
    };
Posted by: Guest on February-07-2021

Code answers related to "C"

Browse Popular Code Answers by Language