Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > searching, creating new file from old using c++

Reply
Thread Tools

searching, creating new file from old using c++

 
 
Michele and John
Guest
Posts: n/a
 
      04-11-2006
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


 
Reply With Quote
 
 
 
 
Michele and John
Guest
Posts: n/a
 
      04-11-2006
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" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
 
Jack Klein
Guest
Posts: n/a
 
      04-11-2006
On Mon, 10 Apr 2006 22:38:14 -0400, "Michele and John"
<(E-Mail Removed)> 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/~a...FAQ-acllc.html
 
Reply With Quote
 
Nick Keighley
Guest
Posts: n/a
 
      04-11-2006

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" <(E-Mail Removed)> wrote in message
> news(E-Mail Removed)...
> > 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
> >
> >


 
Reply With Quote
 
Nick Keighley
Guest
Posts: n/a
 
      04-11-2006
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)

 
Reply With Quote
 
Michele and John
Guest
Posts: n/a
 
      04-13-2006
Thanks everyone for your suggestions.

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

Regards,
Michele


 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      04-13-2006
"Michele and John" <(E-Mail Removed)> 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.velocityreviews.com/forums/(E-Mail Removed) <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.
 
Reply With Quote
 
Michele and John
Guest
Posts: n/a
 
      04-13-2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Michele and John" <(E-Mail Removed)> 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) (E-Mail Removed)

<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.



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
So you think PythonCard is old? Here's new wine in an old bottle. John Henry Python 24 05-30-2008 12:00 AM
searching, creating new file from old using c++ Michele and John C++ 11 04-13-2006 02:46 AM
new hard disk on old, old pc Deano Computer Support 5 10-21-2005 12:32 PM
old printer and old WP in Windows XP? lu Computer Support 6 01-14-2005 02:18 PM
Old file loads in Mozilla, New file in IExplorer Tommy DN Firefox 1 07-04-2004 09:33 AM



Advertisments