Results 1 to 2 of 2

Thread: Structures in C

  1. #1

    Thread Starter
    Hyperactive Member Emo's Avatar
    Join Date
    Jul 2000
    Posts
    428

    Structures in C

    hello all,

    I have a quick question about structures in C and how to properly use them.

    I'm making an Inventory program and i have to show things like what inventory i have, name of part, price, qty on hand.

    I here is the code I have so far declaring them and all:

    Code:
    #define NAME_LENGTH        31
    #define ADDRESS_LENGTH     51
    #define NUMBER_LENGTH      21
    #define PART_LENGTH         6
    #define PRICE_LENGTH        6
    #define QUANTITY_LENGTH     6
    #define TRUE                1
    #define FALSE               0
    
    /* Structure defining a name */
    struct Name
    {
      char firstname[NAME_LENGTH];
    };
    
    /* Structure defining an address */
    struct AddressRecord
    {
      struct Name name;
      char address[ADDRESS_LENGTH];
    };
    
    /* Structure defining an address */
    struct PhoneRecord
    {
      struct Name name;
      char number[NUMBER_LENGTH];
    };
    
    /* Structure defining an part */
    struct PartRecord
    {
      struct Name part;
      char partName[PART_LENGTH];
    };
    
    /* Structure defining an price */
    struct PriceRecord
    {
      struct Name price;
      char price1[PRICE_LENGTH];
    };
    
    /* Structure defining quantity on hand */
    struct QuantityRecord
    {
      struct Name quantity;
      char qty[QUANTITY_LENGTH];
    };
    now, I want to output the part section to the screen and this is giving me trouble.. I was able to show the customer information ok but the rest is not working

    Code:
    /* Outputs the name and number from a phone record */
    //THIS WORKS FINE.....
    void show_record(struct PhoneRecord record)
    {
      printf("\n%s\t%s", record.name.firstname,record.number);
    }
    
    //THIS gives me the errors
    void show_Invrecord(struct PhoneRecord PartRecord)
    {
      printf("\n%s\t%s\t%s", PartRecord.partName,PartRecord.name.price1,PartRecord.name.qty);
    }
    and as you can see I have yet to put in the rest of the info for the customer like the address, and what they bought.

    any help would be appreciated!
    Thank you!

    P.S. Please dont pay attention to my signature... lol as you can see it's been a looong time since been on this site.. haha
    -=VB6 Enterprise Edition=-
    -=VC++6Enterprise Edition=-
    «¤E³m°O²™¤»

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Structures in C

    How have you created the structure variables?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width