Thread: Structures

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    361

    Structures

    I think I'm close, but I can't get the syntax just right.

    Code:
    struct NewQ
    {
            char Q[1000];	//Holds the Question
    	char A[250];	//Holds the Answer
    	char F[250];	//Holds the False Answer (One at a time)
    };
    and I use:

    Code:
    NewQ.Q
    NewQ.A
    NewQ.F
    To access the specific variables. But I get an error, and I'm pretty sure it's with the way the Structure is defined. Is there anything that stands out? Thanks

  2. #2
    Registered User
    Join Date
    Dec 2002
    Posts
    56
    I believe you've defined what a NewQ is, but you haven't created any yet. i.e., somewhere after your structure definition, say:
    Code:
    NewQ theQuestion;
    And then access members using:
    Code:
    theQuestion.Q
    theQuestion.A
    theQuestion.F

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    221
    typedef NewQ thequestion;

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    typedef NewQ thequestion;

    now thequestion is a type, which is equivalent to NewQ. You would still need to declare an instance of thequestion, just like you would need to declare an instance of NewQ before trying to access the values/methods within the instance.

  5. #5
    Registered User happycoder's Avatar
    Join Date
    Jun 2003
    Posts
    6
    typedef NewQ thequestion;
    if youre using C, yes. but in C++, there is no need. just saying
    Code:
    struct NewQ {
    ...
    };
    already defines a new type NewQ.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  2. Structures, passing array of structures to function
    By saahmed in forum C Programming
    Replies: 10
    Last Post: 04-05-2006, 11:06 PM
  3. Input output with structures
    By barim in forum C Programming
    Replies: 10
    Last Post: 04-27-2004, 08:00 PM
  4. pointers to arrays of structures
    By terryrmcgowan in forum C Programming
    Replies: 1
    Last Post: 06-25-2003, 09:04 AM
  5. Methods for Sorting Structures by Element...
    By Sebastiani in forum C Programming
    Replies: 9
    Last Post: 09-14-2001, 12:59 PM