How to find number of structure members in a given structure?

This is a discussion on How to find number of structure members in a given structure? within the C Programming forums, part of the General Programming Boards category; Hi Friends, Is there any method to find the number of structure members in a given structure. And is there ...

  1. #1
    Registered User
    Join Date
    Jan 2012
    Posts
    2

    How to find number of structure members in a given structure?

    Hi Friends,

    Is there any method to find the number of structure members in a given structure.

    And is there any method to check whether a structure member is int or char or string.




    Regards,
    Bhaskar Reddy.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,820
    Why do you need to do this introspection?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jan 2012
    Posts
    2
    Hi LaserLight,

    In my project, i want to receive a struct, and find out how many number of members are there and their types. based on the type i have to call appropriate API to insert that value into a table.

    Regards,
    Bhaskar Reddy.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,820
    Could you embed some kind of type information as a member of the struct?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    Might you have the option of doing this in C++? While it's still not easy or widely scalable, it's certainly easier... much easier.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help using memcpy to update structure members
    By pk68 in forum C Programming
    Replies: 8
    Last Post: 02-27-2011, 05:43 AM
  2. Accessing Structure Members
    By anndruu12 in forum C Programming
    Replies: 5
    Last Post: 12-02-2010, 01:37 AM
  3. How do I point to structure members?
    By RaisinToe in forum C++ Programming
    Replies: 2
    Last Post: 03-07-2009, 10:34 PM
  4. structure members outside main
    By threahdead in forum C Programming
    Replies: 5
    Last Post: 03-09-2003, 06:34 AM
  5. Accessing structure members
    By foniks munkee in forum C Programming
    Replies: 18
    Last Post: 02-13-2002, 02:06 PM

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