CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2011
    Posts
    1

    Printing a specific part of text file into an output file? VERY confused!

    Let's say I have an input file "inputF." In this file we have:

    I 2 3 4 5 2
    W 3 40 0 3 1 2 3
    D 4 59 3 2 9 94 94 220
    P 0 0 0 2 1 3 6
    Q 3 4 2

    U 9 3 2 3
    R 9 3 2 1 3 4
    W 39 9 0 2 1 1 3
    D 3 1 32 3 4 5 91 9
    Q 9 2 1

    For example...
    Now, let's say that I want to print everything that happens after W and before Q in ONLY one case (I would want to print D and P, as in the first case, or just D, as in the second), but I don't necessarily know what's happening in between those letters (I have a defined list of variables to work with, but I have no idea how the actual inputF file will arrange them - they can be in a completely random order). So, basically, I know that I want to print everything that happens between W and Q, but I don't know what's actually between W and Q, or how many lines of text there are between the two letters.

    Thanks!

  2. #2
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Printing a specific part of text file into an output file? VERY confused!

    Pseudo code:

    Code:
    do {
      ReadInputLine();
    } while (!InputLineStartsWith('W'));
    ReadInputLine();
    while (!InputLineStartsWith('Q')) {
      WriteOutputLine();
      ReadInputLine();
    }
    Not really complicated, is it? However, this does not take into account opening and closing of the files as well as special cases like, e.g., either the W line or the Q line or both are missing in the input file. You need to figure out those yourself.
    Last edited by Eri523; October 26th, 2011 at 10:05 AM. Reason: Tiny code syntax fix
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured