![]() |
| | #1 |
| Registered User Join Date: Aug 2003
Posts: 93
| checking values in a text file I am about to change a process that I have been writing recently, and before coding, I thought I would run through the idea here for comments. The process currently reads two text files, (for example september.txt and august.txt) which contain records in the form of strings. The first file has one field checked which contains a text version of a date, and creates one of three new files. The three new files can have the current month, the previous 12 months [not including the current month] and everything else. So there is now a new file, (for example OUT_FILE) which contains just september records. A new check has to be made between OUT_FILE and august.txt on another field which has the text version of an account number. If the acc_id exists in august.txt and not in OUT_FILE, the record is written to a new file, (for example .DEL), if the acc_id exists in OUT_FILE and not in august.txt, the record is written to a new file, (for example .CRE), if the record exists in both files, it is ignored. I thought of reading both files a record at a time and checking the acc_id's [which are guaranteed to be in numerical ascending order] and comparing their value... e.g. Code: file 1 file 2 123 123 124 128 125 129 128 130 129 Code: file 1 file 2
123 123 - 123 = 123 no write
124 128 - 124 < 128 / 124 to .DEL
125 - 125 < 128 / 125 to .DEL
128 - 128 = 128 no write
129 129 - 129 = 129 no write
130 - file 1 EOF everything else in file two written to .CRE
I am not sure if anyone can see any obvious pitfalls in this ? tia, |
| darfader is offline | |
| | #2 |
| End Of Line Join Date: Apr 2002
Posts: 6,240
| The principle looks OK to me. The only pitfall I see is that you are assuming the input is in the correct order. If you are willing to assume this then fine, if there's a chance it won't be, you'll need another method.
__________________ When all else fails, read the instructions. If you're posting code, use code tags: [code] /* insert code here */ [/code] |
| Hammer is offline | |
| | #3 |
| Registered User Join Date: Aug 2003
Posts: 93
| thanks Hammer, I think I'll deliberately sort the files before working on them |
| darfader is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| disposing error | dropper166 | C# Programming | 2 | 03-30-2009 11:53 PM |
| gcc link external library | spank | C Programming | 6 | 08-08-2007 03:44 PM |
| Possible circular definition with singleton objects | techrolla | C++ Programming | 3 | 12-26-2004 10:46 AM |
| Function is called and I am trying to open a file | tommy69 | C Programming | 88 | 05-06-2004 08:33 AM |
| what does this mean to you? | pkananen | C++ Programming | 8 | 02-04-2002 03:58 PM |