I have written a program which updates a master file using a transaction file and creates a new generation of the master file.
I ran the program and cannot get rid of 3 errors - can you give me any clues on how to solve these.
The basic set up of my program is:
typedef struct{
char cust_code [6];
float cust_bal;
long credit_limit;
}MASTER_R;
struct record{
char part_no[7]; /*Have to be char for previous prog*/
char quantity [5];
};
struct record2{
char balance [10];
char limit [8];
};
union account{
struct record old;
struct record2 create;
};
typedef struct{
char code [5];
char blah [6];
union account details;
}cust_rec_st;
cust_rec_st *cust_rec_ptr;
MASTER_R *master_rec_ptr;
Error 1
I want to put the 'balance' from the transaction struct record2 into 'cust_bal' in the master struct. The follwing gave me an error:
master_rec_ptr->cust_bal = cust_rec_ptr->details.create.balance;
Type casting (float) doesn't work. What is another way to do this without getting an error re: type incompatibility?
Error 2
I also want to put the 'limit' from the trans into 'credit_limit' in the master.
master_rec_ptr->credit_limit = cust_rec_ptr->details.create.limit;
This time error is non portable pointer conversion.
Error 3
The following are already set up in a header file. An indexed file so that using the part number you can find the record required.
typedef struct{
char key [7];
float price;
}RECORD_DATA;
typedef struct{
char key [7];
unsigned long rec_num;
}RECORD_INDEX;
A function to read the file is also included in the header file.
The prototype for the function is:
static RECORD_DATA *search_file(char *product_code);
The function is passed the product code and searches the file returning a pointer to the appropriate data structure.
I have therefore written:
float value = 0.0;
RECORD_DATA *stock_rec;
if((stock_rec = search_file(cust_rec_ptr->details.old.part_no)) != NULL)
{
/*the next line is where I get the error*/
value = (float)cust_rec_ptr->details.old.quantity * stock_rec->price;
}
I'm wanting to multiply the quantity from the transaction file with the stock price. Again the type incompatibility.
Any help much appreciated.
Kitten