Thread: C++ program that will search word for match

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    6

    C++ program that will search word for match

    A C++ program that will search word for match, if not found exactly then it will show suggestion.

    For example, in a txt file there are some words (e.g. add, addition, what, advance, but, so, etc.). If a user input a wrong word or spelling, say, 'ad', which is not in the text file, then program will show suggestion (e.g. add, addition, advance).

    How could I write this program (or function) in C++?

    Any suggestion will be appreciated.
    Thanks in advance.

  2. #2

  3. #3
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    I suggest looking into an algorithm called 'Levenshtein Distance', it measures something called the 'edit distance' between 2 strings. If you make your searches match anything below a certain edit distance (between the search string and each of the hits), the user can get away with a typo or two and still get relevant hits. Don't make it too tolerant though, or the searches will start yielding irrelevant hits. It's really simple to implement and works well.
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Word Search Using C
    By CProgramming11 in forum C Programming
    Replies: 15
    Last Post: 11-07-2010, 11:58 PM
  2. An interesting challenge --> A word search program
    By desipunjabi in forum C Programming
    Replies: 5
    Last Post: 11-12-2005, 03:30 PM
  3. Search Sentence for Word?
    By drdroid in forum C++ Programming
    Replies: 4
    Last Post: 02-20-2003, 01:15 PM
  4. Word Search
    By _Cl0wn_ in forum C Programming
    Replies: 2
    Last Post: 01-29-2003, 08:59 AM
  5. open file, search of word, replace word with another
    By Unregistered in forum C++ Programming
    Replies: 0
    Last Post: 06-05-2002, 01:16 PM