Hi,
I have got myself messed up....
I am trying to read two text files which have these structures
which are dumps from database tables. I want to compare the stop date from file one with the stop date from file two connected by RecordIn1.nwcode & RecordIn1.confdna with RecordIn2.dnic & RecordIn2.dna. If the stop date from file one is not found in file two against that key, then it will be written to another file.Code:typedef struct { char bus_tran_code [I_BUS_TRAN_CODE_LEN]; char upddate [I_UPDDATE_LEN]; char rectype [I_RECTYPE_LEN]; char custcode [I_CUSTCODE_LEN]; char usernbr [I_USERNBR_LEN]; char username [I_USERNAME_LEN]; char custname [I_CUSTNAME_LEN]; char nwcode [I_NWCODE_LEN]; char confdna [I_CONFDNA_LEN]; char dnaver [I_DNAVER_LEN]; char gtynbr [I_GTYNBR_LEN]; char fromdate [I_FROMDATE_LEN]; char todate [I_TODATE_LEN]; char rfsdate [I_RFSDATE_LEN]; char billdate [I_BILLDATE_LEN]; char stopdate [I_STOPDATE_LEN]; char invcentre [I_INVCENTRE_LEN]; char billflag [I_BILLFLAG_LEN]; char linkspeed [I_LINKSPEED_LEN]; char prtcoltyp [I_PRTCOLTYP_LEN]; char shared [I_SHARED_LEN]; char linkname [I_LINKNAME_LEN]; char zero1 [I_ZERO1_LEN]; char stopflag [I_STOPFLAG_LEN]; char st_service [I_ST_SERVICE_LEN]; char cnxtype [I_CNXTYPE_LEN]; char zero2 [I_ZERO2_LEN]; char optionflag [I_OPTIONFLAG_LEN]; char cpeflag [I_CPEFLAG_LEN]; char linkcode [I_LINKCODE_LEN]; char site [I_SITE_LEN]; char nodename [I_NODENAME_LEN]; char semicolon1 [I_SEMICOLON1_LEN]; char separator1 [I_SEPARATOR1_LEN]; } RecordIn1; typedef struct { char subscr_no [I_SUBSCR_NO_LEN]; char subscr_no_resets [I_SUBSCR_NO_RESETS_LEN]; char dnic [I_DNIC_LEN]; char dna [I_DNA_LEN]; char ud_user_id [I_UD_USER_ID_LEN]; char inv_ncc [I_INV_NCC_LEN]; char owner_ncc [I_OWNER_NCC_LEN]; char st_servtcode [I_ST_SERVTCODE_LEN]; char bill_date [I_BILL_DATE_LEN]; char stop_date [I_STOP_DATE_LEN]; char stop_core_date [I_STOP_CORE_DATE_LEN]; char order_entry_date [I_ORDER_ENTRY_DATE_LEN]; char rfs_date [I_RFS_DATE_LEN]; char equant_stop_date [I_EQUANT_STOP_DATE_LEN]; char activity_date [I_ACTIVITY_DATE_LEN]; char semicolon2 [I_SEMICOLON2_LEN]; char separator2 [I_SEPARATOR2_LEN]; } RecordIn2;
I have the program opening and closing the files without error, but have come unstuck traversing through the files and checking the fields....
unfortunately, the more I change it, the worse it getsCode:eof1 = fread(&input1, sizeof(RecordIn1), 1, p_fp[IN_FILE1]); if(!eof1) { extracted_records_read++; strncpy(input1_key, input1.nwcode, 15); *(input1_key+15) = NULL; } else memcpy(input1_key, HIGH_VALUE, 15); eof2 = fread(&input2, sizeof(RecordIn2), 1, p_fp[IN_FILE2]); if(!eof2) { exception_records_read++; strncpy(input2_key, input2.dnic, 14); *(input2_key+14) = '0'; *(input2_key+15) = NULL; } else memcpy(input2_key, HIGH_VALUE, 15); while (!eof1 || !eof2) { if(!memcmp(input1_key, input2_key, 15)) { memcpy(&output1, &input1, sizeof(RecordIn1)); memcpy(output1.stop_date, input2.stop_date, 10); fwrite(&output1, sizeof(RecordIn1), 1, p_fp[OUT_FILE1]); extracted_records_written++; exception_records_written++; eof1 = fread(&input1, sizeof(RecordIn1), 1, p_fp[IN_FILE1]); if(!eof1) { extracted_records_read++; strncpy(input1_key, input1.nwcode, 15); *(input1_key+15) = NULL; } else memcpy(input1_key, HIGH_VALUE, 15); eof2 = fread(&input2, sizeof(RecordIn2), 1, p_fp[IN_FILE2]); if(!eof2) { exception_records_read++; strncpy(input2_key, input2.dnic, 14); *(input2_key+14) = '0'; *(input2_key+15) = NULL; } else memcpy(input2_key, HIGH_VALUE, 15); } if(!compare(output1.stop_date, input2.stop_date)) /* write out record */ }
tia,



LinkBack URL
About LinkBacks




