Fix Lesson 2 Task 4

This commit is contained in:
Stanislav Mykhailenko 2024-07-20 15:16:59 +03:00
parent 52c071c46c
commit 8ce7855691
GPG key ID: 1E95E66A9C9D6A36

View file

@ -8,12 +8,17 @@ int main()
cout << "Enter some string: ";
cin.getline(str, 256);
int words = 1;
bool space = false;
for (int character = 0; str[character] != 0; ++character) {
if (str[character] < 'A' || str[character] > 'z') {
if (!space) {
++words;
space = true;
}
} else
space = false;
for (int character = 0; character < 256; ++character) {
if (str[character] == 0)
break;
else if (str[character] < 'A' || str[character] > 'z')
++words;
}
cout << "Number of words: " << words << endl;