Thread: structure matter

  1. #1
    Registered User sureshhewa's Avatar
    Join Date
    May 2008
    Location
    sri lanka
    Posts
    13

    Post structure matter

    Code:
    typedef struct element{
    
    		long int license;
    		char status,type,arrivalTime[SIZE],departureTime[SIZE],duration[SIZE];
    		int moveCount;
    };
    
    
    typedef struct parking{
    		element parkingSlot[SIZE];
    		int front,middle,rear;
    };
    
    main(){
    parking park;
    
    }


    in other function i want to assign a variable (x) to member status

    Code:
    p->parkingSlot[p->rear]->status = x;
    THIS IS WRONG & PLEASE HELP ME TO CORRECT THIS. How should i access member of a structure which is in an array structure

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You have the right idea, but you need to decide if you are working with a pointer or not. Likely you want something like:
    Code:
    p->parkingSlot[p->rear].status = x;
    but there is no indication in your code example as to what p is. Also, note that you need to complete your typedefs, and that main() returns an int, so you should declare it as such. You might also want to explicitly return 0 at the end of main, even though it is not required in C99.
    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 sureshhewa's Avatar
    Join Date
    May 2008
    Location
    sri lanka
    Posts
    13
    thank you laserlight !!! that's the answer . i got your point

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. double pointer to a structure
    By rohit_second in forum C Programming
    Replies: 5
    Last Post: 11-25-2008, 04:32 AM
  2. Problem referencing structure elements by pointer
    By trillianjedi in forum C Programming
    Replies: 19
    Last Post: 06-13-2008, 05:46 PM
  3. Reference to a Structure
    By boschow in forum C Programming
    Replies: 3
    Last Post: 03-28-2008, 02:37 PM
  4. Creating Dynamic Structure in C
    By SomeNath in forum C Programming
    Replies: 1
    Last Post: 03-19-2005, 09:11 AM
  5. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM