structures & data types

This is a discussion on structures & data types within the C Programming forums, part of the General Programming Boards category; I have written a program which updates a master file using a transaction file and creates a new generation of ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    20

    Angry structures & data types

    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

  2. #2
    Registered User jasrajva's Avatar
    Join Date
    Oct 2001
    Posts
    99

    struct record2{
    char balance [10]; <------------------------Look here
    char limit [8];
    };

    typedef struct{
    char cust_code [6];
    float cust_bal; <---------------------and here
    long credit_limit;
    }MASTER_R;

    float and char* are incompatible types so youll need to use


    master_rec_ptr->cust_bal = atof(cust_rec_ptr->details.create.balance);

    double atof( const char *string );

    converts string to a double so that should work for you

    for the second use

    itoa(string)
    this converts string limit in record2 to integer (long)


    couldnt figure out the third one but ill try

  3. #3
    Registered User jasrajva's Avatar
    Join Date
    Oct 2001
    Posts
    99
    hadnt lookd at err3 bfore
    it is obviously the same type incompatibility and the soln is also similar

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 12-05-2008, 02:18 AM
  2. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 11:13 AM
  3. Replies: 8
    Last Post: 03-10-2008, 12:57 PM
  4. Bitmasking Problem
    By mike_g in forum C++ Programming
    Replies: 13
    Last Post: 11-08-2007, 12:24 AM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 07:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21