TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: CLIFF RHODES
from: PAUL DRUGGITT
date: 1997-05-22 02:09:00
subject: passing structures to fu

 -=> Quoting Cliff Rhodes to Paul Druggitt <=-
 Hi Cliff,
 PD> I have tried to pass a void pointer to my function, but cannot
 PD> access  individual members of the structure to perform comparisons.
 CR> If you can do what you want in the function with just one structure
 CR> member, why do you need to pass the entire struct? Just pass the
 CR> member. Or am I missing something in your question?
 My fault!!!
 I was trying to keep the question brief & didn't include enough info
 in my examples to explain what I was trying to do.
 struct RECORD {
     long date        -----> Omitted from original question
     int type;
     char desc[26];
     fpos_t current   -----> Omitted from original question
     fpos_t prev;     -----> Omitted from original question
     fpos_t next;     -----> Omitted from original question
 } DATA;
 struct BIGGER_RECORD {
    long date        -----> Omitted from original question
    int type;
    char desc[26];
    char address_1[40];
    char address_2[40];
    int record_number;
    fpos_t current;  -----> Omitted from original question
    fpos_t prev;     -----> Omitted from original question
    fpos_t next;     -----> Omitted from original question
 } BIGGER_DATA;
 FILE *fp1;
 What I really want to do is :-
     1) Pass ANY structure to a function, stating which member to do
        comparisons on & which file to read/write.
        eg.
        insert_record_in date_order(&BIGGER_DATA, BIGGER_DATA.date, fp1);
        insert_record_in date_order(&DATA, DATA.date, fp1);
     2) Read a record from a file of the same structure as that passed to
        the function.
     3) Compare the member stated in the call to the function with the
        equivalent member in the record just read & change values as
        required.
     while(reading records from the file) {
        if(BIGGER_DATA.date <= RECORD_READ_FROM_FILE.date) {
            BIGGER_DATE.prev    = RECORD_READ_FROM_FILE.prev;
            BIGGER_DATE.next    = RECORD_READ_FROM_FILE.current;
            RECORD_READ_FROM_FILE.prev = BIGGER_DATE.current;
            break;
        }
     }
     4) Rewrite the changed records at their original positions
        & new record at the end of the file
 So the answer to your question is that I want to change the values of
 other members of the structure passed to the function depending on the
 result of a comparison.
 So far I can only do this if I write separate functions for each
 different type of structure. I am trying to write ONE general purpose
 function that I can use for any type of struct, in different programs.
 I hope you now understand. It seems as clear as mud to me.
 Regards,
 Paul Druggitt.
        FIDONET NETMAIL Address   2:250/121
        Internet E-Mail Address   paul.druggitt@fieldbbs.overflow.com
---
---------------
* Origin: The Field BBS * 01706 868997 * 24 Hours V34+ (2:250/121)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.