How to find the occurrence's of a pattern in a given string Using KMP algorithm?

For finding the pattern in a given string , we are going to use KMP algorithm for individual occurrence of the pattern and print the reference index of the original string. The function which will find the pattern in a given string : int KMP(char * str,char* find,int s){ int sl=strlen(str); int fl=strlen(find); for(int i=s;i<sl-fl+1;i++){ int i1=i; for(int j=0;j<fl;j++,i1++){ //cout<<j<<fl<<endl; if(j==fl-1)return i; if(str[i]!=find[j])break; } } return -1; } For finding all the places (positions/index) where the pattern is present, we have to call the above function repetitively with passing the index from where it has to resume the search as a parameter to the function. The same is implemented in the function below: int print_occurence(char* str,char* find){ int sl=strlen(str); int fl=strlen(find); int occ=0; for(int i=0;i<sl;i++){