Fix Lesson 2 Task 4
This commit is contained in:
parent
8ce7855691
commit
bdf1b02fc4
1 changed files with 6 additions and 3 deletions
|
@ -7,17 +7,20 @@ int main()
|
||||||
char str[256];
|
char str[256];
|
||||||
cout << "Enter some string: ";
|
cout << "Enter some string: ";
|
||||||
cin.getline(str, 256);
|
cin.getline(str, 256);
|
||||||
int words = 1;
|
int words = 0;
|
||||||
bool space = false;
|
bool space = false;
|
||||||
|
|
||||||
for (int character = 0; str[character] != 0; ++character) {
|
for (int character = 0; str[character] != 0; ++character) {
|
||||||
if (str[character] < 'A' || str[character] > 'z') {
|
if (str[character] < 'A' || str[character] > 'z') {
|
||||||
if (!space) {
|
if (!space && words != 0) {
|
||||||
++words;
|
++words;
|
||||||
space = true;
|
space = true;
|
||||||
}
|
}
|
||||||
} else
|
} else {
|
||||||
space = false;
|
space = false;
|
||||||
|
if (words == 0)
|
||||||
|
++words;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue