Thread: Word from a string...

  1. #1
    random number generator reRanger's Avatar
    Join Date
    Oct 2004
    Posts
    44

    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
    "Nay! But you love the present life!"

  2. #2
    Registered User
    Join Date
    Aug 2004
    Posts
    66
    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

  3. #3
    random number generator reRanger's Avatar
    Join Date
    Oct 2004
    Posts
    44
    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
    "Nay! But you love the present life!"

  4. #4
    random number generator reRanger's Avatar
    Join Date
    Oct 2004
    Posts
    44
    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
    "Nay! But you love the present life!"

  5. #5
    Registered User
    Join Date
    Aug 2004
    Posts
    66
    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

  6. #6
    Registered User
    Join Date
    Aug 2004
    Location
    San Diego, CA
    Posts
    313
    Actually, to compare strings, your best bet is the strcmp() function.

  7. #7
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    I think strcmp( ) is specific to the <cstring> library.. However when using the <string> library, the binary operators such as == and += should be used.
    Last edited by The Brain; 11-22-2004 at 09:42 AM.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  8. #8
    random number generator reRanger's Avatar
    Join Date
    Oct 2004
    Posts
    44

    Talking ty

    Thanks Lithorien and Brain.
    reRanger
    "Nay! But you love the present life!"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hangman game and strcmp
    By crazygopedder in forum C Programming
    Replies: 12
    Last Post: 11-23-2008, 06:13 PM
  2. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 06:02 AM
  3. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM
  4. can anyone see anything wrong with this code
    By occ0708 in forum C++ Programming
    Replies: 6
    Last Post: 12-07-2004, 12:47 PM
  5. length of string etc.
    By Peachy in forum C Programming
    Replies: 5
    Last Post: 09-27-2001, 12:04 PM