can anybody please help me with a program to find the number of words in a given sentence , no matter how many spaces are inbetween.......
Or atleast give me a clue.....
can anybody please help me with a program to find the number of words in a given sentence , no matter how many spaces are inbetween.......
Or atleast give me a clue.....
A clue? Sure... operator>> parses out data according to whitespace.
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens
You can use std::string::find_first_of() in a loop.
This is just a clue, I'm not going to write the whole thing for you.Code:#include <iostream> #include <string> using namespace std; int main() { string eg = "this and that"; size_t pos = 0; while ((pos = eg.find_first_of(" \t",pos)) != eg.npos) { cout << pos << eg.substr(pos) << endl; pos++; } return 0; }
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge