searching, creating new file from old using c++

Discussion in 'C Programming' started by Michele and John, Apr 11, 2006.

  1. I would like to write a C++ program that searches for the variable "state !=
    0" in a text file, and then go back 3 steps each time to read "count". The
    program should create a new file with "state count". The data in the old
    file is variable, but could be as follows:

    old_file.txt
    new_file.txt
    state count
    state count
    0 22
    1 83
    0 83 <-
    1 13
    0 13
    1 34
    0 34
    1 33
    1 33
    1 23
    1 31
    1 66
    1 23 <-
    3 63
    1 66
    3 37
    0 45
    3 88
    1 22
    3 66
    1 98
    3 36
    0 13
    0 73
    0 53
    0 63 <-
    0 37
    0 88
    3 66
    3 36
    3 33
    3 88
    3 67
    0 45
    0 35
    0 44

    Any help will be greatly appreciated.

    Regards,
    Michele
     
    Michele and John, Apr 11, 2006
    #1
    1. Advertising

  2. Sorry, the formatting is messed up.

    I would like to write a C++ program that searches for the variable
    "state != 0" in a text file, and then go back 3 steps each time to read
    "count". The
    program should create a new file with "state count". The data in the old
    file is variable, but could be as follows:

    old_file.txt
    state count
    0 22
    0 83 <-
    0 13
    0 34
    1 33
    1 31
    1 23 <-
    1 66
    0 45
    1 22
    1 98
    0 13
    0 73
    0 53
    0 63 <-
    0 37
    0 88
    3 66
    3 36
    3 33
    3 88
    3 67
    0 45
    0 35
    0 44



    new_file.txt
    1 83
    1 13
    1 34
    1 33
    1 23
    1 66
    3 63
    3 37
    3 88
    3 66
    3 36


    Any help will be greatly appreciated.

    Regards,
    Michele

    "Michele and John" <> wrote in message
    news:...
    > I would like to write a C++ program that searches for the variable "state

    !=
    > 0" in a text file, and then go back 3 steps each time to read "count". The
    > program should create a new file with "state count". The data in the

    old
    > file is variable, but could be as follows:
    >
    > old_file.txt
    > new_file.txt
    > state count
    > state count
    > 0 22
    > 1 83
    > 0 83 <-
    > 1 13
    > 0 13
    > 1 34
    > 0 34
    > 1 33
    > 1 33
    > 1 23
    > 1 31
    > 1 66
    > 1 23 <-
    > 3 63
    > 1 66
    > 3 37
    > 0 45
    > 3 88
    > 1 22
    > 3 66
    > 1 98
    > 3 36
    > 0 13
    > 0 73
    > 0 53
    > 0 63 <-
    > 0 37
    > 0 88
    > 3 66
    > 3 36
    > 3 33
    > 3 88
    > 3 67
    > 0 45
    > 0 35
    > 0 44
    >
    > Any help will be greatly appreciated.
    >
    > Regards,
    > Michele
    >
    >
     
    Michele and John, Apr 11, 2006
    #2
    1. Advertising

  3. Michele and John

    Jack Klein Guest

    On Mon, 10 Apr 2006 22:38:14 -0400, "Michele and John"
    <> wrote in comp.lang.c:

    > I would like to write a C++ program that searches for the variable "state !=
    > 0" in a text file, and then go back 3 steps each time to read "count". The
    > program should create a new file with "state count". The data in the old
    > file is variable, but could be as follows:


    [snip]

    If you want to write a C++ program, why the blue blazes are you
    cross-posting to comp.lang.c?

    They are two different languages, you know, and C++ is completely
    off-topic in comp.lang.c.

    Kindly be more polite in the future.

    Followup set.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://c-faq.com/
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
     
    Jack Klein, Apr 11, 2006
    #3
  4. Michele and John wrote:
    > Sorry, the formatting is messed up.
    >
    > I would like to write a C++ program that searches for the variable
    > "state != 0" in a text file, and then go back 3 steps each time to read
    > "count". The
    > program should create a new file with "state count". The data in the old
    > file is variable, but could be as follows:
    >
    > old_file.txt
    > state count
    > 0 22
    > 0 83 <-
    > 0 13
    > 0 34
    > 1 33
    > 1 31
    > 1 23 <-
    > 1 66
    > 0 45
    > 1 22
    > 1 98
    > 0 13
    > 0 73
    > 0 53
    > 0 63 <-
    > 0 37
    > 0 88
    > 3 66
    > 3 36
    > 3 33
    > 3 88
    > 3 67
    > 0 45
    > 0 35
    > 0 44
    >
    >
    >
    > new_file.txt
    > 1 83
    > 1 13
    > 1 34
    > 1 33
    > 1 23
    > 1 66
    > 3 63
    > 3 37
    > 3 88
    > 3 66
    > 3 36
    >
    >
    > Any help will be greatly appreciated.
    >
    > Regards,
    > Michele
    >
    > "Michele and John" <> wrote in message
    > news:...
    > > I would like to write a C++ program that searches for the variable "state

    > !=
    > > 0" in a text file, and then go back 3 steps each time to read "count". The
    > > program should create a new file with "state count". The data in the

    > old
    > > file is variable, but could be as follows:
    > >
    > > old_file.txt
    > > new_file.txt
    > > state count
    > > state count
    > > 0 22
    > > 1 83
    > > 0 83 <-
    > > 1 13
    > > 0 13
    > > 1 34
    > > 0 34
    > > 1 33
    > > 1 33
    > > 1 23
    > > 1 31
    > > 1 66
    > > 1 23 <-
    > > 3 63
    > > 1 66
    > > 3 37
    > > 0 45
    > > 3 88
    > > 1 22
    > > 3 66
    > > 1 98
    > > 3 36
    > > 0 13
    > > 0 73
    > > 0 53
    > > 0 63 <-
    > > 0 37
    > > 0 88
    > > 3 66
    > > 3 36
    > > 3 33
    > > 3 88
    > > 3 67
    > > 0 45
    > > 0 35
    > > 0 44
    > >
    > > Any help will be greatly appreciated.
    > >
    > > Regards,
    > > Michele
    > >
    > >
     
    Nick Keighley, Apr 11, 2006
    #4
  5. Michele and John wrote:
    > Sorry, the formatting is messed up.
    >
    > I would like to write a C++ program that searches for the variable
    > "state != 0" in a text file, and then go back 3 steps each time to read
    > "count". The
    > program should create a new file with "state count". The data in the old
    > file is variable, but could be as follows:
    >
    > old_file.txt
    > state count
    > 0 22
    > 0 83 <-
    > 0 13
    > 0 34
    > 1 33
    > 1 31
    > 1 23 <-
    > 1 66
    > 0 45
    > 1 22
    > 1 98
    > 0 13
    > 0 73
    > 0 53
    > 0 63 <-
    > 0 37
    > 0 88
    > 3 66
    > 3 36
    > 3 33
    > 3 88
    > 3 67
    > 0 45
    > 0 35
    > 0 44
    >
    >
    >
    > new_file.txt
    > 1 83
    > 1 13
    > 1 34
    > 1 33
    > 1 23
    > 1 66
    > 3 63
    > 3 37
    > 3 88
    > 3 66
    > 3 36
    >
    >
    > Any help will be greatly appreciated.


    <snip repeated initial post>

    grep "1 " old_file.txt

    (ok there are better REs but I can't be bothered to look it up)

    if you *really* have to write a program take a look at strstr().
    if you *really* have to do it in C++ then try comp.lang.c++. I'd
    guess std::string would be a place to start.


    --
    Nick Keighley

    "High Integrity Software: The SPARK Approach to Safety and Security"
    Customers interested in this title may also be interested in:
    "Windows XP Home"
    (Amazon)
     
    Nick Keighley, Apr 11, 2006
    #5
  6. Thanks everyone for your suggestions.

    I implemented the solution using variations of the STL vector...

    Regards,
    Michele
     
    Michele and John, Apr 13, 2006
    #6
  7. "Michele and John" <> writes:
    > Thanks everyone for your suggestions.
    >
    > I implemented the solution using variations of the STL vector...


    The parent article was posted only to comp.lang.c++. Why did you
    cross-post your followup to comp.lang.c?

    And please read <http://cfaj.freeshell.org/google/>.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Apr 13, 2006
    #7
  8. Keith,
    > The parent article was posted only to comp.lang.c++. Why did you
    > cross-post your followup to comp.lang.c?


    If you paid attention to detail, you would have noticed that I posted the
    original article to both comp.lang.c++,comp.lang.c
    Why did you cross-post to comp.lang.c?

    Michele.

    "Keith Thompson" <> wrote in message
    news:...
    > "Michele and John" <> writes:
    > > Thanks everyone for your suggestions.
    > >
    > > I implemented the solution using variations of the STL vector...

    >
    > The parent article was posted only to comp.lang.c++. Why did you
    > cross-post your followup to comp.lang.c?
    >
    > And please read <http://cfaj.freeshell.org/google/>.
    >
    > --
    > Keith Thompson (The_Other_Keith)

    <http://www.ghoti.net/~kst>
    > San Diego Supercomputer Center <*>

    <http://users.sdsc.edu/~kst>
    > We must do something. This is something. Therefore, we must do this.
     
    Michele and John, Apr 13, 2006
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jim Hill
    Replies:
    3
    Views:
    411
    Jim Hill
    Feb 12, 2007
  2. Searching for old LLIBCDLL.LIB

    , Apr 25, 2005, in forum: C Programming
    Replies:
    0
    Views:
    288
  3. Michele and John
    Replies:
    11
    Views:
    453
    Michele and John
    Apr 13, 2006
  4. *Prot3anThr3ad*

    old repository for old C++ source code

    *Prot3anThr3ad*, Sep 29, 2006, in forum: C++
    Replies:
    6
    Views:
    390
    *Prot3anThr3ad*
    Oct 2, 2006
  5. John Henry
    Replies:
    24
    Views:
    1,027
    alex23
    May 30, 2008
Loading...

Share This Page