Thread: search words

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    18

    search words

    Here is the code:
    Code:
    /*
    void FindWord()	// find a word from puzzle
    	{
    		std::vector<std::string>::const_iterator iter_start = wordlist.begin();
    		std::vector<std::string>::iterator iter_end = wordlist.end();
    		//std::vector<PuzzleRow> row = 0;
    		//std::vector<PuzzleRow> col = 0;
    		
    		for (iter_start; iter_start != iter_end; ++iter_start)
    		{
    			for (PuzzleLetters::size_type i = 0; i < puzzleletters.size(); ++i)
    			{
    				for (PuzzleRow::size_type j = 0; j < puzzleletters[i].size(); ++j)
    				{
    					if ((wordlist[j][0]) == puzzleletters[i][j])
    					{
    						//LookupLister::lookup(*iter_start , puzzleletters, i, j)  // look up a word
    						if (wordlist[j].size() <= puzzleletters[i].size() - col)  // enough room ?
    						{
    							int k = 0;
    							while (wordlist[j][++k] == puzzleletters[i][++j]);
    							std::cout << "Found a word \n";
    						}
    						
    					}	
    					//else
    						//std::cout << "Word not found ! \n";
    				}
    			}
    		}
    			*/
    I am trying to find a word from the puzzle by comparing each character at a time. What is the better way for comparing each character and see if the word is found in the puzzle? The puzzle contains many characters.

  2. #2
    Registered User
    Join Date
    Aug 2002
    Posts
    170
    You can use strstr() this finds a string within a string.

    if( strstr(Puzzle,Word) != NULL )
    {
    //found one
    }
    Best Regards,

    Bonkey

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. exhaustive graph search
    By Cpro in forum C++ Programming
    Replies: 6
    Last Post: 04-20-2008, 11:08 AM
  2. Firefox and Google Search
    By DeepFyre in forum Tech Board
    Replies: 0
    Last Post: 01-16-2005, 10:28 AM
  3. Simple search program
    By colinuk in forum C Programming
    Replies: 6
    Last Post: 12-18-2004, 01:58 AM
  4. string pattern search problem
    By goron350 in forum C Programming
    Replies: 6
    Last Post: 11-25-2004, 08:50 AM
  5. Again Character Count, Word Count and String Search
    By client in forum C Programming
    Replies: 2
    Last Post: 05-09-2002, 11:40 AM