1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

How to store struct in an array?

Discussion in 'C' started by boschow, Feb 21, 2008.

  1. boschow

    boschow New Member

    Joined:
    Feb 22, 2007
    Messages:
    32
    Likes Received:
    0
    Trophy Points:
    0
    Hi all,
    it is possible to store structs in an array.

    Lets say that i have 5 structus. All 5 of m have different elements. And i need all their elements stored in an array? See example below:

    Code:
    typedef struct
    {
        int a;
        int b;
    }Math;
    
    typedef struct
    {
       unsigned a:1;
       unsigned b:1;
       unsigned c:1;
    }coils;
    
    typedef struct
    {
      char name1;
      char name2;
      char name3;
    }names;
    
    Now i am asking you if it is possible to write an array (see example below) in C programing language?

    Code:
    char var[9] = {{Math.a}, {Math.b}, {coils.a}, {coils.b}, {coils.c}, {nemes.name1}, {names.name2}, {names.name3}, {names.name4}};
    
    Best Regards,
    BoSCHoW.
     

Share This Page