Thread: Search Sentence for Word?

  1. #1
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    Question Search Sentence for Word?

    After I saw that RoD was working on RoDBot, on the irc, I looked back at my old chatbot code. Mine was crap. So I'm starting from scratch. Does anyone know of a function that searches a sentence for a specific word?

  2. #2
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Look up std::string::find()

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    What container does the words reside in? For character arrays, one solution is strstr(). For bytes, one solution is memchr().

    Kuphryn

  4. #4
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    Theres two good ways imo to go about this:

    1) txt files
    2) enums

    I would use the function eibro suggested if your not using txt files. While buggy as it is as far as error checking goes, my code is 100% open source. Feel free to ask any questions u may have, and i will try my best to help.

    Heres the latest cpp, not many changes, just a few fixes. convo() is getting totally rebuilt tonight.

  5. #5
    jvasher
    Guest
    Hash table.


    Sorry not sure if this c standard. use it so much.


    try this if its in std c++

    string word, tbuff = " This is my string to find the word string";
    int pos;

    pos = tbuff.Pos( "string" );
    word = tbuff.substr( pos, tbuff.Length() );

    or tbuff.Delete( pos, tbuff.Length() );

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  3. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 09:40 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM