Displaying the name of the structure?

This is a discussion on Displaying the name of the structure? within the C Programming forums, part of the General Programming Boards category; Hi, Is there a way to display the name of the structure, rather than its contents?? suppose we have Code: ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    103

    Displaying the name of the structure?

    Hi,
    Is there a way to display the name of the structure, rather than its contents??
    suppose we have
    Code:
    typedef struct{
                          int x;
                          char s[123];
                          }account;
    and I want to print out the world "account".
    PS: In my case, there is several structures, that is why typing their names manually will be difficult..

  2. #2
    Registered User
    Join Date
    Apr 2008
    Posts
    103
    So no idea!???

  3. #3
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    You mean during run-time? No, no standard way at least. You'd need to store it as a member. You could do something like:
    Code:
    #ifdef DEBUG
    const char *sname_account = "struct account";
    #endif
    ...
    typedef struct{
    #ifdef DEBUG
    const char *sname;
    #endif
    int x;
    char s[123];
    }account;
    
    account myacc;
    #ifdef DEBUG
    myacc.sname = sname_account;
    #endif
    Then define DEBUG when you want to keep track of the structure names, but it's nothing pretty as a permanent solution, only really useful for debugging.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help displaying info from structure
    By kisiellll in forum C Programming
    Replies: 6
    Last Post: 04-04-2009, 01:51 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  3. Displaying Data from a Nested Structure
    By shazg2000 in forum C++ Programming
    Replies: 1
    Last Post: 01-09-2005, 10:16 AM
  4. displaying data from a structure of arrays
    By Unregistered in forum C Programming
    Replies: 8
    Last Post: 03-14-2002, 12:35 PM
  5. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21