#include "stdio.h"
#include "conio.h"
#include "iostream.h"
#include "string.h"
void main(){
char sentence[100];
cout<<"Enter the sentence : ";
gets(sentence);
int length=strlen(sentence);
char find[20];
cout<<"masukan kata yang ingin di cari : ";
gets(find);
int length2=strlen(find);
int count;
int count2=0;
int word=1;
for(int i=0; i<length; i++){
count=0;
if(sentence[i]==' '&& sentence[i+1]!=' '){
word++;
}
for(int j=0; j<length2&&(sentence[i+j]==find[j]); j++){
count++;
}
if(count==length2){
cout<<"ditemukan pada word ke-"<<word<<endl;
cout<<"ditemukan mulai array ke "<< i<<endl;
count2++;
i+=(length2-1);
}
}
cout<<"ditemukan "<<count2<<" yang cocok"<<endl;
getch();
}
0 komentar:
Posting Komentar