Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cstring>
- using namespace std;
- int wcount(string str)
- {
- bool f;
- int i, word;
- word = 0;
- f = false;
- for(i = 0; str[i] != '\0'; i++)
- if (str[i] != ' ' && f == false)
- {
- word++;
- f = true;
- }
- else if (str[i] == ' ') f = false;
- return word;
- }
- /*void word_count(string str)
- {
- int c = 0;
- //cout << str.length() << endl;
- for (int i = 0; i < strlen(str.c_str()) / 2; i++)
- if (((int)str[i] >= 97) && ((int)str[i] <= 122) || (((int)str[i + 1] == 32) || str[i + 1] == '\0')) c++;
- cout << c;
- }*/
- int main()
- {
- string str;
- getline(cin, str);
- //word_count(str);
- int k = wcount(str);
- cout << k;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement