Thread: checking values in a text file

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    93

    checking values in a text file

    Hi,

    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
    would be processed like this
    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
    Each field value would be sent to an if test for evaluation and then decide on which file the record would be written to.

    I am not sure if anyone can see any obvious pitfalls in this ?


    tia,

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    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]

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    93
    thanks Hammer,

    I think I'll deliberately sort the files before working on them

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. disposing error
    By dropper166 in forum C# Programming
    Replies: 2
    Last Post: 03-30-2009, 11:53 PM
  2. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  3. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  4. Function is called and I am trying to open a file
    By tommy69 in forum C Programming
    Replies: 88
    Last Post: 05-06-2004, 08:33 AM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM