Thread: Struct Association

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    I would think you should nest them like this:

    Code:
    struct product {
    	char description[128];
    	float price;
    	char id[12];
    };
    
    struct cust {
    	char name[32];
    	char address[128];
    	int id;
            struct product bought[5];
    } customer[50];
    So you now have, for example, customer[7].bought[2].price referring to the cost of the 2nd product for customer 7...if each product also has it's own struct (declared "struct product sparetire"), you just do this to create the bought products:

    Code:
    customer[7].bought[2] = sparetire;
    Last edited by MK27; 10-01-2008 at 07:10 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Segfault with Linked List Program
    By kbrandt in forum C Programming
    Replies: 1
    Last Post: 06-23-2009, 07:13 AM
  2. Global Variables
    By Taka in forum C Programming
    Replies: 34
    Last Post: 11-02-2007, 03:25 AM
  3. Replies: 10
    Last Post: 05-18-2006, 11:23 PM
  4. What's wrong with my search program?
    By sherwi in forum C Programming
    Replies: 5
    Last Post: 04-28-2006, 09:57 AM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM