finding entered word number in entered sentence

hello. i need a help with my program. i have to input a sentence then a word. my program should find the number of entered word in sentence:
for example : i love apple. apple is good. apple is perfect :p
word: apple
count of apple: 3
please help me with my code

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
  #include <iostream>
using namespace std;
int length(char str[]){
	int count = 0;
	while(str[count] != NULL && count < 81){
		count ++;
	}
	return count;}
int main (void){
	char sentence[81], iteration[81];
	int count, letters = 0, space = 0, another = 0, i =0;
	gets(sentence);
	cout << "enter a word" << endl;
	gets(iteration);
	char word[]=" ";
		while(sentence[i]!=NULL){
			if(sentence[i]= iteration[letters]) letters++;
			else if(sentence[i] = ' ') space ++;
			else another++;
			i++;
		}
		count = (length(sentence)-space-another)/space;
	cout << count << endl;
	return 0;
}
http://en.cppreference.com/w/cpp/string/byte/strstr
1
2
3
4
5
6
7
int n = 0;
char* check = sentence;
char* result = nullptr;
while (result = strstr(check, iteration)) {
    check = ++result;
    ++n;
}
i need a solution only with iostream library
int main (void){
char sentence[81];
char iteration[81];
int count;
int letters = 0;
int space = 0;
int another = 0;
int i =0;
gets(sentence);
cout << "enter a word" << endl;
gets(iteration);
while( sentence[i] != NULL ){
if(isEqual(sentence, iteration) == 1){
count ++;}
/*else if( isEqual(sentence, iteration) == 0 )*/
i++;}

cout << count << endl;
//cout << count << endl;
return 0;
}
Topic archived. No new replies allowed.