Printing Structure Element

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • piyushnewe
    New Member
    • Mar 2010
    • 2

    Printing Structure Element

    I have structure. I am storing data in the below structure. But for some reason I would like to Print/Get Information of the Element of the EMPdata structure.
    Code:
    typedef struct
    {
       int empid;
       char empname[100];
       int dept;
       char date_join[15];
    } EMPdata;
    In other words I would like to PRINT the name of the elements of the Structure e.g. as below

    empid
    empname
    dept
    date_join

    Can we do it in "C" ?

    Share your views.
  • Dheeraj Joshi
    Recognized Expert Top Contributor
    • Jul 2009
    • 1129

    #2
    Sure. Go through this link. You will get some idea how it can be done.

    And for more info Google

    Regards
    Dheeraj Joshi

    *Note: Please use code tag while post the code.

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      If you mean can you print the names of the members of the structure rather than the values of the members of the structure in C automatically without just hardcoding those names into strings then no there is no way to do that.

      Comment

      • piyushnewe
        New Member
        • Mar 2010
        • 2

        #4
        Thanks Banfa..

        You got the correct Question. Yeah I mean so.

        no work around ?? :(

        Comment

        • Banfa
          Recognized Expert Expert
          • Feb 2006
          • 9067

          #5
          Not without writing an external program to parse your structures for you and automatically produce the code.

          Comment

          Working...