#include <iostream>
#define lim 256
using namespace std;
char s1[lim];
char s2[lim];
char c;
int strlen(char s[]);
int get_num(char s_1[], char s_2[]);
int main()
{
do
{
int index=0;
cout<<"Enter the string "<<endl;
for (index=0; index<lim && (c=getchar())!=EOF && c!="\n";++index)
s1[index]='\0';
cout<<endl;
cout<<"Enter the word="<<endl;
index=0;
for (index=0; index<lim && (c=getchar())!=EOF && c!="\n";++index)
s2[index]='\0';
}
while (strlen(&s2[0]) > strlen(&s1[0]));
cout<<"word frequency="<<endl;
cout<<&s2[0]<<" "<<get_num(&s1[0], &s2[0])<<endl;
system("pause");
return 0;
}
int strlen(char s[])
{
int i = 0;
while (s[i] != '\0')
++i;
return i;
}
int get_num(char s_1[], char s_2[])
{
int n_o = 0;
int i = 0, kol_words = 0, index = 0;
int x_word = 0; int mas[lim];
for (i = 0; i<strlen(&s_1[0]);i++)
{
if(s_1[i] == ' ' && i > 0)
{
++kol_words;
mas[index] = x_word;
}
}
mas[index+1] = i-1;
x_word = i+1;
++index;
}
}
++kol_words; mas[index] = x_word; mas[index+1] = i-1;
int g = 0; int j;
for (int i = 0; i < kol_words * 2; i++)
{
x_word = mas[i+1] - mas[i]+1;
if (strlen(&s_2[0]) == x_word)
{
g = mas[i]; index = 0;
for (j = 0; j < x_word; j++)
{
if (s_1[g] != s_2[j]) { j = x_word; index = 0; }
if (s_1[g] == s_2[j]) ++index;
++g;
}
}
if (index == x_word) ++n_o;
}
++i;
}
return n_o;
}