-
Word from a string...
Hello:
I have what is probably a simple question, although I have searched hard for an example and have found none on the Net thus far. I am working on the beginnings of a program which will rely heavly upon the ability for the computer to scan the typed input from a user; a particular (or "trigger word) if present in the input string should be found and selected (should it exist at all) This word when discovered will initiate a response. Example: The trigger word is "feel"// user inputs "I do not know how you feel about this but..." Program reads input and captures "feel" in turn causing reaction.
I am the type of person that hates to ask for help (I'd rather figure it out myself, but...) Any help would be greatly appreciated.
Cheers
reRanger
-
after getting the complete line of text you could separate each word by using the spaces, then, each word is placed in a certain array and compare each one with the original word, I believe the function that recognizes spaces is in ctype.h
-
Thank-you, louis_mine.
I have come across that today online, I believe, and I may have been overlooking other info as well. I am somewhat new to programming and I absolutely love it to the point of obsession at times. Thanks again.
reRanger
-
One question:
If I parse a string and seperate the words into specific, reserved arrays, I then could compare them to the trigger word, say, "feel". Would "feel" need to be declared as a const var? Also, are sub-strings able to be compared like intergers, "cat==cat" or "dog!=cat"?
reRanger
-
feel can be declared as a char*, i am not sure if as constant.
You can compare strings, however it has to be for example:
if ("cat"=="cat") //using " " for strings, simple characters like just one letter use ' ' .
I hope that helps
-
Actually, to compare strings, your best bet is the strcmp() function.
-
I think strcmp( ) is specific to the <cstring> library.. However when using the <string> library, the binary operators such as == and += should be used.
-
ty
Thanks Lithorien and Brain.
reRanger