quick question

This is a discussion on quick question within the C++ Programming forums, part of the General Programming Boards category; How would I be able to find certain words in a word search given in a specific file. The words ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    18

    quick question

    How would I be able to find certain words in a word search given in a specific file. The words are also stored in another file. Here is the code I have so far:
    Code:
    #include<iostream>
    #include<iomanip>
    #include<fstream>
    #include<conio>
    #include<string>
    #include<cstring>
    
    using namespace std;
    
    void FileCheck(ifstream&, char[]);
    void ReadWMatrix(ifstream&, char wmatrix[25][25]);
    void ReadWords(ifstream&, string words[25]);
    void PrintOut(char wmatrix[25][25], string words[25]);
    
    int main()
    {
      ifstream input;
      char wmatrix[25][25];
      string words[25];
         
    ReadWMatrix(input, wmatrix);
    ReadWords(input, words);
    PrintOut(wmatrix, words);
       
    return 0;
    }
    /*******************************************************/
    void FileCheck(ifstream& In,char Name[])
    {
       do
       {
       cout << "File not found\n";
       cout << "Enter File Name >";
       cin >> Name;
       In.open(Name); 
       }
       while (In.fail());  
    }
    /*******************************************************/
    void ReadWMatrix(ifstream& input, char wmatrix[25][25])
    {
      input.open("wmatrix.dat");
      while(!input.eof())
      {
        for(int i=0; i<19; i++)
           for(int j=0; j<21; j++)
              input >> wmatrix[i][j];
      }
      input.close();
    }
    /*******************************************************/
    void ReadWords(ifstream& input, string words[25])
    {
      input.open("words.dat");
      while(!input.eof())
      {
        for (int i=0; i<25; i++)
           input >> words[i];
      }
      input.close();
    }
    /*******************************************************/
    void PrintOut(char wmatrix[25][25], string words[25])
    {
        for(int i=0; i<19; i++)
        {
           for(int j=0; j<21; j++)
    		 cout << wmatrix[i][j];
    		 cout << endl;
        }
    
      for(int i=0; i<25; i++)
      {
         cout << words[i];
         cout << endl;
      }
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    > char wmatrix[25][25];
    > string words[25];
    Why not use an array of strings for both?

    > while(!input.eof())
    Read the FAQ on why using eof() in a control loop is bad.

    > Here is the code I have so far:
    Yeah, and what is your question?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    18
    "How would I be able to find certain words in a word search given in a specific file?"

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    Declare a container to hold all the words you want to search for. Read entire content of appropriate file into the container. Then read the file to search one word at a time. Search the container of words for the current word. If current word found in container of words do something. Go to the next word in the file to search.
    You're only born perfect.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very quick math question
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 10-26-2005, 11:05 PM
  2. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 03:48 AM
  3. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 04:44 AM
  4. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 11:04 AM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21