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 11 2251
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" <ph************ **@comcast.net> wrote in message
news:xJ******** ************@co mcast.com... 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
On Mon, 10 Apr 2006 22:38:14 -0400, "Michele and John"
<ph************ **@comcast.net> 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.l earn.c-c++ http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jack Klein wrote: On Mon, 10 Apr 2006 22:38:14 -0400, "Michele and John" <ph************ **@comcast.net> 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.
anyone remember the old anti-grumpiness campaign?
--
Nick Keighley
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" <ph************ **@comcast.net> wrote in message news:xJ******** ************@co mcast.com... 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 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,
Thanks for your advice.
Does strstr() have the ability to search for a string at the current line in
a text file, and if there is a match
1) copy the string at the current line n, and also
2) copy strings at a previous line? e.g. n-3
Please let me know your thoughts.
Regards,
Michele
"Nick Keighley" <ni************ ******@hotmail. com> wrote in message
news:11******** **************@ z34g2000cwc.goo glegroups.com.. . 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)
please don't top post. I have re-arranged your post accordingly.
Also trim all but essentials from what you are replying to.
Michele and John wrote: "Nick Keighley" <ni************ ******@hotmail. com> wrote in message news:11******** **************@ z34g2000cwc.goo glegroups.com.. . 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 file is variable, but could be as follows:
old_file.txt state count 0 22 0 34 1 33 1 66 0 45
much shortened example
new_file.txt 1 33 1 66
<also much shotened>
<snip>
grep "1 " old_file.txt
(ok there are better REs but I can't be bothered to look it up)
so why don't you use grep?
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.
do you want C or C++? They are different languages. I have only
given a C answer.
Does strstr() have the ability to search for a string at the current line in a text file, and if there is a match
no. as 20s with google woul have shown you. Use fgets() to read a line
and
strstr() to find a string within it.
1) copy the string at the current line n, and also 2) copy strings at a previous line? e.g. n-3
why do you need to do this to solve your problem. And what does
"eg. n-3" mean?
--
Nick Keighley
Nick Keighley wrote: old_file.tx t state count 0 22 0 34 1 33 1 66 0 45 much shortened example
but wrong
new_file.tx t 1 33 1 66
<also much shotened>
and equally wrong
<snip> grep "1 " old_file.txt
(ok there are better REs but I can't be bothered to look it up)
so why don't you use grep?
Because your solution is wrong. It can't be done with grep alone. The
requirement was, that at encountering a state not equal to zero, the
value three lines above should be output. It's, however, trivial in
scripting languages like awk:
awk '$1 { print $1, old3 }
{ old3=old2; old2=old1; old1=$1; } ' old_file.txt
This can be easily translated into C++, which is left as an exercise to
the reader (OP)
Christian
Thanks everyone for your suggestions.
I implemented the solution using variations of the STL vector...
Regards,
Michele This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Michi |
last post by:
Hello,
I am creating a databse with a large number of text (or blob?)
entries. I want users to be able to search these fields.
An example would be a forum or journal. Indexing every word in the
post seems costly. If I have 100,000 posts over a few months, and each
one has 50 words in it, that is a 500,000 match entries. The databse I
will be creating will be even larger. For longer posts, there is a
huge overhead of dozens of INSERT...
|
by: Mike |
last post by:
Sites using thumbnail preview for world wide web file navigation and
searching.
Below are list of sites that are either researching or providing thumbnail
preview images for online web documents. Thumbnail previews are useful for
web site navigation particularly in search engines and directories such as
Google, Altavista and Yahoo. The preview images provide a portion of the
content of the electronic file to aid in navigation.
|
by: googleboy |
last post by:
Hi there.
I have defined a class called Item with several (about 30 I think)
different attributes (is that the right word in this context?). An
abbreviated example of the code for this is:
class Item(object):
def __init__(self, height, length, function):
params = locals()
|
by: Geoff Jones |
last post by:
Hiya
I have a DataTable containing thousands of records. Each record has a
primary key field called "ID" and another field called "PRODUCT" I want to
retrieve the rows that satisy the following criteria:
I have a list of about 100 numbers which correspond to the ID field and also
another 40 say numbers corresponding to the numbers in the PRODUCT field. I
want to show the rows that correspond to both these criteria.
|
by: Michele and John |
last post by:
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
| |
by: pbd22 |
last post by:
Hi.
I am somewhat new to this and would like some advice.
I want to search my xml file using "keyword" search and
return results based on "proximity matching" - in other words,
since the search string will often not produce a direct match,
the results will be based on proximity (50%, 20% 100%, etc).
are there any good examples out there on how to do keyword
searches on XML data? How should i set up my xml file so
|
by: Hunk |
last post by:
Hi
I have a binary file which contains records sorted by Identifiers
which are strings. The Identifiers are stored in ascending order. I
would have to write a routine to give the record given the Identifier.
The logical way would be to read the record once and put it in an STL
container such as vector and then use lower_bound to search for a
given identifier. But for some strange reason i'm asked to not use a
container but instead...
|
by: Seongsu Lee |
last post by:
Hi,
I have a dictionary with million keys. Each value in the
dictionary has a list with up to thousand integers.
Follow is a simple example with 5 keys.
dict = {1: ,
2: ,
900000: ,
900001: ,
|
by: Ahmad Jalil Qarshi |
last post by:
Hi,
I have a text file having size about 2 GB. The text file format is like:
Numeric valueAlphaNumeric values
Numeric valueAlphaNumeric values
Numeric valueAlphaNumeric values
For example consider following chunk of actual data:
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| | |