Другие языки программирования и технологии

C++ сторки

Нужно найти количество букв о в 2 слове фразы, которая состоит из 3 слов. Помогите написать часть кода. Вот заготовка:
#include "stdafx.h"
#include "iostream"
#include "conio.h"
#include
using namespace std;
void main()
{
char string[100];
char *p;
int K;
int N1,N2,M=0;
int z;
cout«"vvedi stroky\n"; //VVOD
cin.getline(string,100);
K=strlen(string);
for (int z=0;z<K;z++) //poisk imeni
if (string[z] == ' ')
{
M=M++;
if (M==1) N1=z;
if (M==2) N2=z;
}
for ( z=N1; z<N2;z++)
{

cout«string[z];

}

system("pause");
}
#include "stdafx.h"
#include "iostream" // не в кавычках, а в < >
using namespace std;

int main()
{
char str[100];
int amount = 0;
setlocale(0, "rus");
cout << "Введите фразу латиницей: ";
cin.getline(str, 100);
char * explode = strtok(str, " ");
explode = strtok(NULL, " ");
for(int i = 0; i < strlen(explode); i++)
{
if(explode[i] == 'O' || explode[i] == 'o')
amount++;
}
cout << "Всего \"O\" во второй фразе = " << amount << "\n";
system("pause");
}
Андрей Кацага
Андрей Кацага
3 314
Лучший ответ
Ну тогда уж если strtok и плевать на многопоточность ^___^. Если юзать C++ 11, то можно было бы чуть изящнее.
#include < iostream >
#include < algorithm >
#include < cstring >

using namespace std;

bool isO (char c) { return toupper(c)=='O'; }

int main (int argc, char *argv[])
{
const char cDelimiters[] = " ,.;?!:";

string text = "Hello woOorld again!";

char * token = strtok((char*)text.c_str(), cDelimiters);
if (token)
if (token = strtok(NULL, cDelimiters)) {
cout <<
"Word: " << token << endl <<
"Count: " << count_if(token, token + strlen(token), isO) << endl;
}
return 0;
}
Ivan Krapivin
Ivan Krapivin
84 764
#include "stdafx.h"
#include "iostream"
#include "conio.h"
#include
using namespace std;
void main()
{
int y=0;
char string[100];
char *p;
int K;
int N1,N2,M=0;
int z;
cout«"vvedi stroky\n"; //VVOD
cin.getline(string,100);
K=strlen(string);
for (int z=0;z<K;z++) //poisk imeni
if (string[z] == ' ')
{
M=M++;
if (M==1) N1=z;
if (M==2) N2=z;
}
for ( z=N1; z<N2;z++)
{

cout«string[z];
if (string[z]=='O' || string[z]=='o')
{
y=y++;
}

}

cout<<"kolichestvo bykv o "<< y;
}
}

system("pause");
}