hi : )
I wrote this code for count a specific word selected by user in an array
but it have a logic error ..
and also is there another way to write it without using pointer ?
#include<iostream>
using namespace std;
int j,i=0;
const int size=500;
char array1[size],search[100],*cnt;
//------------
void word();//count a specific word select by user
int main()
{
cout<<"**** ..enter your text.. ****"<<endl;
gets(array1);
word();
return 0;
}
void word()
{
int count=0;
cout<<"enter the word that you want to count"<<endl;
cin>>search;
for ( i = 0; i <= 100; ++i ) {
cnt = &array1[ i ];
while ( cnt = strstr( cnt, search ) ) {
++count;
++cnt;
}
}
cout<<count;
}
please, help me :(