Advertisement
Guest User

Untitled

a guest
Apr 25th, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cstring>
  4.  
  5. using namespace std;
  6.  
  7. int countWords(char *sentence);
  8.  
  9. int main()
  10. {
  11. const int size=80;
  12. char word[size];
  13. double average=0;
  14. cout<<"Enter words less than " <<size-1<<" characters."<<endl;
  15. cin.getline(word, size);
  16. cout <<"There are "<<countWords(word)<<" words in the sentence."<<endl;
  17.  
  18. return 0;
  19. }
  20.  
  21. int countWords(char *sentence)
  22. {
  23. int words= 1;
  24. while(*sentence != '')
  25. {
  26. if(*sentence == ' ')
  27. words++;
  28. sentence++;
  29. }
  30. return words;
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement