Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Pattern Matching

Reply
Thread Tools

Pattern Matching

 
 
kittykat
Guest
Posts: n/a
 
      12-02-2004
Hi,

I want to read the input variables from a user, and then compare this with
data in the text file. If the input variables and the data in the text file
match, then i would like to create a vector to store this information as
binary.

Is there anyone who can help me please? I am a beginner in C++, and I have
so far figured out how to read input from a user. I have a very long way to
go, and I only have a week to do this. Any help would be greatly
appreciated.

Thanx.

 
Reply With Quote
 
 
 
 
rossum
Guest
Posts: n/a
 
      12-03-2004
On Thu, 02 Dec 2004 14:50:28 -0500, "kittykat"
<(E-Mail Removed)> wrote:

>Hi,
>
>I want to read the input variables from a user, and then compare this with
>data in the text file. If the input variables and the data in the text file
>match, then i would like to create a vector to store this information as
>binary.


Putting your problem into pseudocode gives:

read user-input from keyboard
read file-data from text-file
if (user-input matches file-data) then
store binary-information in information-vector
endif

Looking at the code you posted earlier, just keeping the good bits:

#include <fstream>
#include <string>
#include <iostream>

using namespace std;

int main()
{
// Get input from user
string pattern;

cout << "Enter the item you are searching for: ";
cin >> pattern;


// Read data from file
ifstream myFile("data.txt");


// Have we found a match?

// Store binary information

system("pause");

}

Using comments as place holders can help. The comments reflect the
pseudocode so everything should be in the right place. The line
system("pause"); is not entirely standard, and hence non-portable. It
is a way of stopping the console screen disappearing before you have
had time to read it. It will work on MS Windows.

When you are having problems don't try to solve all of them at once.
Work through them one at a time. Start with reading the file. In
your earlier code you used getline(), which is the correct way to read
a single line from a file. However a file may have more than one line
so you need to put getline() into a loop so you can read all of the
lines in the file. You are going to have to think about where to keep
each line as you read it, you don't want the next line to overwrite
the previous line before you have had a chance to look for a match.
At some point you are going to reach the end of the file, so you are
also going to have to detect the end of the file and exit the loop
gracefully.

Once you can read the file successfully then start thinking about how
to look for a match.

>Is there anyone who can help me please? I am a beginner in C++, and I have
>so far figured out how to read input from a user. I have a very long way to
>go, and I only have a week to do this. Any help would be greatly
>appreciated.
>
>Thanx.


--

The ultimate truth is that there is no Ultimate Truth
 
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
Help with Pattern matching. Matching multiple lines from while reading from a file. Bobby Chamness Perl Misc 2 05-03-2007 06:02 PM
Matching neighbouring words of a pattern using Regex CV Perl 2 08-31-2004 12:27 AM
Pattern matching : not matching problem Marc Bissonnette Perl Misc 9 01-13-2004 05:52 PM
Pattern matching help! grep emails from file! danpres2k Perl 3 08-25-2003 02:47 PM
A newbie question on pattern matching DelphiDude Perl 3 07-26-2003 12:54 PM



Advertisments