This repository has been archived on 2024-10-24. You can view files and clone it, but cannot push or open issues or pull requests.
NG_2024_Stanislav_Mykhailenko/Lesson_2/Task_4/main.cpp

31 lines
596 B
C++
Raw Normal View History

2024-06-24 15:19:29 +00:00
#include <iostream>
using namespace std;
int main()
{
char str[256];
cout << "Enter some string: ";
cin.getline(str, 256);
2024-07-20 12:26:07 +00:00
int words = 0;
2024-07-20 12:16:59 +00:00
bool space = false;
for (int character = 0; str[character] != 0; ++character) {
if (str[character] < 'A' || str[character] > 'z') {
2024-07-20 12:26:07 +00:00
if (!space && words != 0) {
2024-07-20 12:16:59 +00:00
++words;
space = true;
}
2024-07-20 12:26:07 +00:00
} else {
2024-07-20 12:16:59 +00:00
space = false;
2024-07-20 12:26:07 +00:00
if (words == 0)
++words;
}
2024-06-24 15:19:29 +00:00
}
cout << "Number of words: " << words << endl;
return 0;
}