Does anyone know how to search for words within a specific sentence using strings? Here's an example of what I mean.
I'm using visual c++ 6.0.Code:The word: back The sentence: I'll be back.
Edit: or to check for words within a sentence.
Does anyone know how to search for words within a specific sentence using strings? Here's an example of what I mean.
I'm using visual c++ 6.0.Code:The word: back The sentence: I'll be back.
Edit: or to check for words within a sentence.
go character by character?..or go by words...white space separate words (tabs, end-line, space)..
nextus, the samurai warrior
I'm with PJ.
At this level, use find().
Also, investigate 'basic_string'. The member functions that you'll find will surprise/amaze you.
(Why they're not used more often is a mystery to me, though I understand the implicit rationale behind "grunt work". Learn the basics, then...appreciate the functionality of the language.)
-Skipper
"When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow
ok, in one of the headers, <iostream> or <cstdio> is the strtok() function
it takes in 2 parameters
1 - is the string you want to find words for
2 - is a set that represents every deliminating character
the deliminating character is over written by '\0' then str is passed back.
char *strtok(char *str, const char *set);
every subsequent call after the initial needs str to be passed NULL.
char str[] = "Hello and Welcome back!";
char set[] = "\\ \'\",.!?"; // and whatever else
char *tok;
then...
tok = strtok(str, set);
then...
tok = strtok(NULL, set);
This is because every subsequent call with NULL, tells strtok to start back where str left off... it then repeats and sends back another pointer... until str reaches the Null-Terminating character...
Great function for parsing through sentences to find words.
I reccomend always to write every function that you plan to use yourself, so that way you get a better understanding of the code.