string search

This is a discussion on string search within the C++ Programming forums, part of the General Programming Boards category; Hello, I need some help on searching a string. Given a list of nouns = dog, cat and bird. And ...

  1. #1
    Registered User blackwyvern's Avatar
    Join Date
    Jan 2002
    Posts
    60

    Post string search

    Hello, I need some help on searching a string.

    Given a list of nouns = dog, cat and bird.
    And a list of verbs = ran, scrurried, flew.
    I am giving my program an input of a sentence, "The dog ran."
    I need a way to do a search of each individual word of the sentence, Look at the word "the" check it against the list, look at the word "dog" check it against the list, and the word ran. I am trying to create a natural language system, but I am starting on a very rudimentary system first. Is there a way to search the first string up until the space and so forth?

  2. #2
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385
    searching the boards will find everything you need
    http://www.cprogramming.com/cboard/s...der=descending
    Monday - what a way to spend a seventh of your life

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    65
    Use strstr
    The experimenter who does not know what he is looking for will not understand what he finds.
    - Claude Bernard

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    60
    char buffer[BUFSIZE];
    char*word[number_words_evalu);
    int a,b,leng,helper,nr_word;
    for(b=0;b<nr_words_evalu;b++)
    word[b]=NULL;
    cin.getline(buffer,BUFSIZE);
    leng=strlen(buffer);
    helper=0,nr_word=0;
    for(a=0;a<leng;a++){
    if(buffer[a]==' '){
    word[nr_word]=new char[a-helper+1];
    for(b=0;b<a-helper+1;b++){
    word[nr_word][b]=buffer[b+helper];
    if(b==a-helper)
    word[nr_word][b]='\0';}
    nr_word++;
    if(a!=leng-1)
    helper=a+1;
    }

    This prog fragment should help you a little bit.
    All words are stored in the word-array, so that they can be compared with stored-anywhere_before words (file,fstream...);
    Last edited by Mecnels; 01-25-2002 at 08:50 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  2. Custom String class gives problem with another prog.
    By I BLcK I in forum C++ Programming
    Replies: 1
    Last Post: 12-18-2006, 02:40 AM
  3. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 09:33 PM
  4. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 10:06 PM

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