
Сообщение от
gru74ik
3. Лучше использовать пре-инкремент (вот так: ++count):
Код C++
1
count++
это ведь не имеет значения без выражения
в любом случае если кому интересно - рабочий код :
C++ |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
| #include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
void t(string str)
{
bool word = true;
int count = 0;
if (str == "")
{
cout << "String is empty\n";
}
int size = str.length();
for (int i = 0; i<size; ++i)
{
if (str[i] == ' ')
{
word = true;
}
if ((str[i] == 'b' || str[i] == 'B') && word)
{
word = false;
count++;
}
}
cout << "\n" << count<<endl;
}
int _tmain(int argc, _TCHAR* argv[])
{
char d[80];
cout << "Enter string" << endl;
cin.getline(d, 80);
cout << d;
t(d);
system("pause");
} |
|