Thread: Help working with pointers

  1. #1
    Registered User
    Join Date
    Jul 2015
    Posts
    9

    Help working with pointers

    Hello,


    I have a product sales management program where I have a structure for storing product data, another to store customer data and another to store sales data. When I insert a new sale has to be associated with a existing product serial number and the id of a existing customer. How do i guarantee when data products and customers struct are changed the sales struct is updated?

    Here's what I have:

    Code:
    typedef struct{
    
    char serialnumber[10]
    char description[100]
    float price
    }stproducts;
    
    typedef struct{
    int id;
    char name[50]
    char adress[100]
    int phonenumber
    }stcustomers;
    
    typedef struct{
    int idcustomersale;
    char serialnumberproductsale[10]
    float endprice;
    }stsales;
    Code:
    int main()
    {
       stproducts pr[1000];
       int countproducts =0;
       stcustomers cust[500];
       int countcustomers=0; 
       stsales sal[1000];
       int countsales=0;
    
    }

    part of the function insert sale:

    Code:
    void insertsale(stsales sal[], int *countsales, stproduct pr[], int countproduct,stcustomers cust[], int countcustomers)
    {
    char psale[10];
    int number;
    
     consultproducts(pr, countproducts);
     consultcustomers(cust,countcustomers);
     printf("insert the product serial number of the sale:");
     fgets(psale, sizeof psale, stdin);
     strcpy(sal[*countsales].serialnumberproductsale,psale);
     printf("insert the customer id of the sale:");
     scanf ("%d", &number);
     sal[*countsales].idcustomersale=number;
    
    //....................
    
    
    }
    For example let's imagine that the id field is changed on the customer struct, automatically the customer id associated with the sale (idcustomersale) must also be updated.


    please help !!!!

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    As Aslaville said in your other thread, "you have to do that yourself."

    If a value is changed, and as a result other values have to be updated, it is up to you [the programmer] to ensure all those other fields are updated as needed.

  3. #3

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. working with void pointers
    By Delia in forum C Programming
    Replies: 6
    Last Post: 03-30-2010, 11:45 PM
  2. working with pointers to structures
    By Delia in forum C Programming
    Replies: 2
    Last Post: 03-21-2010, 05:23 PM
  3. Replies: 3
    Last Post: 09-22-2005, 10:49 AM
  4. Working with pointers...
    By CompiledMonkey in forum C++ Programming
    Replies: 2
    Last Post: 05-09-2005, 08:14 AM

Tags for this Thread