Like Tree1Likes
  • 1 Post By Neo1

C++ program that will search word for match

This is a discussion on C++ program that will search word for match within the C++ Programming forums, part of the General Programming Boards category; A C++ program that will search word for match, if not found exactly then it will show suggestion. For example, ...

  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
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,528
    Manasij Mukherjee | gcc-4.9.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  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.
    mcoder likes this.
    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, 02:16 PM

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