Thread: Nested Structure help ~

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    31

    Nested Structure help ~

    First, I should show the question first...

    (i) Using typedef, declare a structure called employee which can hold the following details of an employee.
    ID
    Name
    Position

    (ii) Using the keyword struct (without typedef), declare a structure called Wrk to store the employee working record consisting of the following details. (You must make use of the structure declared in part (i) above.)
    Emp (as in (i) above)
    Rate
    Hours
    Basic


    (iii) Define an array, called EmpWrk, of 10 structures of typeWrk declared in part(ii) above. Initialize the first two records as follows:
    ID Name Position Rate Hours Basic
    771122 Mike Wong Programmer 4.62 40 1800.00
    345906 Bill John Manager 8.51 38 2400.00

    __________________________________________________ _______

    My coding so far....

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
        typedef struct {
    
            char ID[30];
    
            char Name[30];
    
            char Position;
    
        } employee ;
    
        struct{
    
            employee Emp;
    
            int rate;
    
            int hours;
    
            int basic;
    
        } Wrk;
    
      
    
    
      int main(void)
    
        {
            
    
    
    
    
    
    
            return 0;
    
        }
    __________________________________________________ _______
    I was stuck at (iii), can someone show me how to define that array like (iii) have mention? Very thanks you.


  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Don't you think it's about time you started figuring this stuff out on your own?

    Seriously... Didn't we just cover all this in another thread?

    FWIW... that is one contiguous block of information. Putting it in nested structs is *stupid*... all it does is make the data harder to access. I realize that's your assignment, but you would never find coding like this in the real world...
    Last edited by CommonTater; 10-09-2011 at 02:33 AM.

  3. #3
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Quote Originally Posted by Siaw View Post
    I was stuck at (iii), can someone show me how to define that array like (iii) have mention? Very thanks you.
    Just declare an array of "struct Wrk", and set the two first to the information given. What don't you understand?
    Devoted my life to programming...

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by GReaper View Post
    Just declare an array of "struct Wrk", and set the two first to the information given. What don't you understand?
    I'm thinking he's going to do this --playing helpless-- just long enough to get us to do his homework for him.

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Why did you start a new thread with the same exact title as your old thread for the same exact type of problem?


    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by quzah View Post
    Why did you start a new thread with the same exact title as your old thread for the same exact type of problem?
    Quzah.
    Because he didn't learn anything from the last one?

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by CommonTater View Post
    Because he didn't learn anything from the last one?
    Well clearly I don't need to waste any more time on the subject then, regardless of how many new threads he makes!


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Nested Structure help ~
    By Siaw in forum C Programming
    Replies: 32
    Last Post: 10-09-2011, 01:48 AM
  2. pointer to nested structure
    By wahid in forum C Programming
    Replies: 2
    Last Post: 11-10-2010, 04:05 AM
  3. Displaying Data from a Nested Structure
    By shazg2000 in forum C++ Programming
    Replies: 1
    Last Post: 01-09-2005, 10:16 AM
  4. initializing nested structure arrays
    By linucksrox in forum C Programming
    Replies: 2
    Last Post: 06-10-2004, 10:58 PM
  5. nested structure help
    By whistler in forum C Programming
    Replies: 1
    Last Post: 05-17-2002, 10:48 AM