Thread: Help with structures

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    38

    Help with structures

    Okay I'm going to make a C program (definitely not a homework this time) to keep track of timber (using structures) and I need your assistance.

    Each unit of timber has got an identification code consisting of:
    Zone - a character representing the zone of the tree:
    Code:
    char zone;
    ID - a 10-character identification number
    Code:
    int ID[10];
    Then I will define a structure called TimberIDType that contain the above information.

    I would like to store the ff. information for each of the timber unit:

    TimberID - of TimberIDType above
    Kind - a 30-character description of the timber
    Code:
    char Kind[30];
    Diameter, Weight and Height - float numbers that tell about the timber's dimensions
    Code:
    float Diameter, Weight, Height;
    My program should be able to store up to 100 TimberRec records in an array called TimberArray.

    My program should perform the ff. operations:

    1. Add a new record into TimberArray
    2. Display all records
    3. Display a particular record given the Kind
    4. Display records given the Weight
    5. Display records given the TimberID

  2. #2
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    So what excatly are the peices of it you are having problems with? Post any code you have done along with any errors and we can help.
    Double Helix STL

  3. #3
    Registered User
    Join Date
    Jul 2008
    Posts
    38
    heres a draft part of the code it isnt finished yet.

    Code:
    #include <stdio.h>
    #include <string.h>
    
    struct TimberIDType
    {
        char Zone;
        int ID[10];
    }
    
    char Kind[30];
    float Diameter, Weight, Height;
    Last edited by mkdl750; 07-19-2008 at 12:55 AM.

  4. #4
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    What do you need help with? (No question in that post, and the forum won't write the code for you - we help with any trouble you have.)

    ID - a 10-character identification number
    Code:
    int ID[10];
    That's 10 integers, not a 10-digit number. 32 bit number can store 9 base-10 digits... alternatively, a string representation? Example of an ID number?

    Also, what does "ff" mean? I could apply anything I found here...

    EDIT: okay, was writing when others posted. You know you can put structs in structs, right?:
    Code:
    struct TimberUnit
    {
       TimbwerIDType id;
       char Kind[30];
       float Diameter, Weight, Height;
    };
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  5. #5
    Registered User
    Join Date
    Jul 2008
    Posts
    38
    ff stands for "following" in this thread.

  6. #6
    Registered User
    Join Date
    Jul 2008
    Posts
    38
    Okay, any further assistance so that I can put the segments into a fully-functional program? Please, I want it done by Monday (I'm not kidding).

  7. #7
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    You have a deadline to finish this by Monday, and it's not homework? Why oh why do I doubt you?

  8. #8
    System.out.println("");
    Join Date
    Jan 2005
    Posts
    84
    Quote Originally Posted by MacGyver View Post
    You have a deadline to finish this by Monday, and it's not homework? Why oh why do I doubt you?
    I did a search and someone posted a very similar question on Daniweb last April. It most definitely is HW.

  9. #9
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    I vote that for lying to us we either:

    1. Refuse to help him..... or
    2. Give him wrong information.



  10. #10
    Registered User
    Join Date
    Jul 2008
    Posts
    38
    We'll talk about this later.

  11. #11
    Registered User
    Join Date
    Jul 2008
    Posts
    38
    I did NOT say that you are going to post the codes. I said that you can give me assistance, hints or advice regarding my program. Sorry about saying that it's not homework. Actually I'm making this C program to practice myself in making structures. I'm NOT the person who posted that similar topic on Daniweb last April because I don't have an account there.

    By the way, I'll post the "primitive" codes, and you can proofread them and send hints or any assistance.

    By the way I actually set the deadline on Monday for myself. I can extend it no matter what I'm doing.
    Last edited by mkdl750; 07-19-2008 at 06:01 PM.

  12. #12
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    ID should be an array of char, not an int array, as Cactus_Hugger mentioned:
    char id[10]; and all the dimension data should also go inside your struct:

    char Kind[30];
    float Diameter, Weight, Height;

    Because every piece of timber will have that same type of info.

  13. #13
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by MacGyver View Post
    I vote that for lying to us we either:

    1. Refuse to help him..... or
    2. Give him wrong information.


    Miss Manners would never approve.

    I don't see how it could have hurt anyone, so let's consider it a little white lie, and being the gentlemen (and ladies) that we are, understand that everyone uses such lies, from time to time, for purely good social reasons.

    And simply pretend we didn't hear (or read) it. What lie?

  14. #14
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Hmm, I wonder if I should start an offtopic poll in General Discussion asking how many people thought I was serious.

    Of course a vote of 100&#37; in one direction would kind of ruin the idea of such a poll.....

  15. #15
    Registered User
    Join Date
    Jul 2008
    Posts
    38
    As of this point in time I have defined the necessary structures and variables.

    Here's what will the main menu will look like:

    Code:
    {...
    //main menu
    int choice1;
    
    printf("\nWhat would you like to do?");
    printf("\n[1] Add new timber record");
    printf("\n[2] Display all records");
    printf("\n[3] Display particular record(s) by kind");
    printf("\n[4] Display particular record(s) by Weight");
    printf("\n[5] Display particular record(s) by TimberID");
    printf("\nInput choice: ");
    scanf("&#37;d",&choice1);
    ...}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  2. Structures within Structures
    By Misko82 in forum C Programming
    Replies: 2
    Last Post: 08-27-2007, 12:25 AM
  3. Structures, passing array of structures to function
    By saahmed in forum C Programming
    Replies: 10
    Last Post: 04-05-2006, 11:06 PM
  4. Structures, and pointers to structures
    By iloveitaly in forum C Programming
    Replies: 4
    Last Post: 03-30-2005, 06:31 PM
  5. Methods for Sorting Structures by Element...
    By Sebastiani in forum C Programming
    Replies: 9
    Last Post: 09-14-2001, 12:59 PM