Pattern Matching

Discussion in 'C++' started by kittykat, Dec 2, 2004.

  1. kittykat

    kittykat Guest

    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.
     
    kittykat, Dec 2, 2004
    #1
    1. Advertising

  2. kittykat

    rossum Guest

    On Thu, 02 Dec 2004 14:50:28 -0500, "kittykat"
    <> 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
     
    rossum, Dec 3, 2004
    #2
    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. DelphiDude
    Replies:
    3
    Views:
    1,188
  2. danpres2k
    Replies:
    3
    Views:
    7,519
    danpres2k
    Aug 25, 2003
  3. CV
    Replies:
    2
    Views:
    607
    Charles DeRykus
    Aug 31, 2004
  4. Marc Bissonnette

    Pattern matching : not matching problem

    Marc Bissonnette, Jan 8, 2004, in forum: Perl Misc
    Replies:
    9
    Views:
    260
    Marc Bissonnette
    Jan 13, 2004
  5. Bobby Chamness
    Replies:
    2
    Views:
    261
    Xicheng Jia
    May 3, 2007
Loading...

Share This Page