Structures question: How do I show information inside a structure?

This is a discussion on Structures question: How do I show information inside a structure? within the C++ Programming forums, part of the General Programming Boards category; How do I show all of the variables + their single structure names that are within a structure type to ...

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    23

    Structures question: How do I show information inside a structure?

    How do I show all of the variables + their single structure names that are within a structure type to the user?
    Last edited by Warrax; 05-05-2007 at 06:28 AM.

  2. #2
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    first, your post is quite confusing to difficult to understand.

    you use '.' (period) to access members of the struct. if the struct is a pointer you use '->' ('indirect member selection' operator). to show the information, you use the same method you would for showing any other information.

  3. #3
    Registered User
    Join Date
    Mar 2007
    Posts
    23
    Fixed; it should be easier to understand, now, :-).

  4. #4
    Registered User
    Join Date
    Apr 2006
    Posts
    2,023
    Same way you would a class. Write a meathod or function that prints everything that you need out.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    There is no automated way to print the name and value of all struct members: the name is no longer available at runtime.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Registered User
    Join Date
    Oct 2005
    Posts
    271
    Just out of curiosity, would there be a way of writing a program such that if it were compiled into a debug version (i.e. with the symbolic tables embedded), the program be able to look into its own symbolic table?

    I mean, a vague idea would be
    Code:
    int main(int argc, char* argv[])
    {
           FILE* f = fopen(argv[0], "r"); //so here you'd pass its own self as an argument
           look_in_the_symbolic_table_of_the_file_,_format_it_and_print_it_out(f);
    }

  7. #7
    aoeuhtns
    Join Date
    Jul 2005
    Posts
    581
    argv[0] doesn't necessarily contain the filename of the program in question.
    There are 10 types of people in this world, those who cringed when reading the beginning of this sentence and those who salivated to how superior they are for understanding something as simple as binary.

  8. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    > the program be able to look into its own symbolic table?
    Theoretically, yes. Examples of such programs are called debuggers.

    But if you only have one or two such structures, then its much easier to roll the code yourself.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  9. #9
    Registered User
    Join Date
    Oct 2005
    Posts
    271
    argv[0] doesn't necessarily contain the filename of the program in question.
    Is it shell specific? At least in Bash and Windows, I think you always get the name of the executable or script.

  10. #10
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    It always includes the filename, but it may also include the path or a partial path.

  11. #11
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    And the filename in question might specify a symbolic link.

    Oh, and the filename is looked up in the PATH, whereas fopen doesn't look, which means that if you don't call the program with an explicit path, it won't find the executable in the fopen call.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  12. #12
    Registered User
    Join Date
    Oct 2005
    Posts
    271
    Right, I'd forgotten that executables have to be in the path to run. I guess you could do some kind of combo with getenv and searching for the file in each of the path directories.

    Symbolic links... Can't see any way around that. Oh well, recursive self-reference is always interesting.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pthread question how would I init this data structure?
    By mr_coffee in forum C Programming
    Replies: 2
    Last Post: 02-23-2009, 11:42 AM
  2. Structure and Linked List User Input Question
    By kevndale79 in forum C Programming
    Replies: 16
    Last Post: 10-05-2006, 11:09 AM
  3. Special Allegro Information
    By TechWins in forum Game Programming
    Replies: 12
    Last Post: 08-20-2002, 11:35 PM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  5. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 09:52 AM

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