Thread: Use variable to specify structure field

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    Are all the fields the same type?

    What are you trying to do?
    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.

  2. #2
    Registered User
    Join Date
    Mar 2006
    Posts
    4
    im sorting an array of structures. there are 5 fields - one long and 4 ints. The structures will be ordered in the array by one of the 4 int fields in them, and the user selects which one to sort by. Basically, I want to be able to pass this

    fieldvariable = "field1";


    ....

    then refer later in code to the field denoted by the variable

    e.g.

    if fieldvariable is as above, I could have

    Code:
    structure.fieldvariable
    would be seen by the program as
    Code:
    structure.field1

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Printf: somehow it changed a structure field.
    By Artemiy in forum C Programming
    Replies: 3
    Last Post: 04-04-2009, 11:27 AM
  2. Problem with structure with a float variable
    By j.sreejit in forum C Programming
    Replies: 9
    Last Post: 12-29-2006, 01:23 AM
  3. i am not able to figure ot the starting point of this
    By youngashish in forum C++ Programming
    Replies: 7
    Last Post: 10-07-2004, 02:41 AM
  4. Replies: 12
    Last Post: 10-14-2003, 10:17 AM
  5. Variable is not a structure and Sort char **
    By ChazWest in forum C Programming
    Replies: 1
    Last Post: 03-08-2002, 09:40 AM