468,512 Members | 1,360 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

how to find whether the input string is meaningful

8
I'm writing a C program where the user enters a string and the program aims at finding whether the input string is meaningful English word or not. Comparing each and every input word with the dictionary words kept in another file is highly impossible. Is there any another way to do this?
Jan 11 '08 #1
7 3296
sicarie
4,677 Expert Mod 4TB
I'm writing a C program where the user enters a string and the program aims at finding whether the input string is meaningful English word or not. Comparing each and every input word with the dictionary words kept in another file is highly impossible. Is there any another way to do this?
Why is that impossible?
Jan 11 '08 #2
Chuthu
8
Why is that impossible?
What I assumed was to keep a list of all meaningful English words in a separate text file and get the usr input.The user may enter any text and any amount of text at run rime. To check if each entered word is meaningful or not, it has to be compared with every word in the text file and if it matches, it's meaningful or else it's not. But is it really feasible to have all the words in the dictionary (which may run to lakhs of words) in a file and check for text matching? Is there a better alternative for this?
Jan 11 '08 #3
weaknessforcats
9,207 Expert Mod 8TB
To check if each entered word is meaningful or not, it has to be compared with every word in the text file
Yes there is. It comes down to your lookup. If a words starts with H, maybe you only check the words that start with H and not then entire dictionary.

Here's where functions can help you.

You an write a Lookup() that does a complete dictionary search and call it to find a word. Later you can rewrite Lookup() to do a more efficicent search. Then all you need to is recompile your code to use the new function.
Jan 11 '08 #4
Chuthu
8
Yes there is. It comes down to your lookup. If a words starts with H, maybe you only check the words that start with H and not then entire dictionary.

Here's where functions can help you.

You an write a Lookup() that does a complete dictionary search and call it to find a word. Later you can rewrite Lookup() to do a more efficicent search. Then all you need to is recompile your code to use the new function.

Okay. Searching can be narrowed down. But can all the words found in the dictionary be made to fit in the file?
Jan 12 '08 #5
weaknessforcats
9,207 Expert Mod 8TB
Probably. Do understand a dictionary does not have to be in one file. You could have a lot of files and those files could be organized as trees so you don't have to search the entire file evey time.
Jan 12 '08 #6
Chuthu
8
Probably. Do understand a dictionary does not have to be in one file. You could have a lot of files and those files could be organized as trees so you don't have to search the entire file evey time.
Can you please tell me how to organize the collection of files as a tree hierarchy?
Jan 13 '08 #7
weaknessforcats
9,207 Expert Mod 8TB
You just use a file rather than memory for your tree:

Expand|Select|Wrap|Line Numbers
  1. struct Word
  2. {
  3.      char theWord[20];
  4.      char theDefinition[500];
  5.      size_t  theLocation;           //seek to this for theWord
  6.      //Left:
  7.      size_t   Left;                    //seek to this for the next word less in sequence
  8.      //Right
  9.     size_t    Right;                  //seek to this for the next word greater in sequence
  10.  
  11.  
  12. };
  13.  
New words are always added to the end of the file.

Off you go, and your tree is now a disc file.
Jan 13 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Paul E Collins | last post: by
4 posts views Thread by Johannes Busse | last post: by
3 posts views Thread by zhi lin | last post: by
3 posts views Thread by David Marsh | last post: by
4 posts views Thread by cdrom205 | last post: by
2 posts views Thread by willie | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.