#include <stdio.h>
int find_substr(char *listPointer, char *itemPointer);
int main(void)
{
if(find_substr(“C is fun”, “is”) != -1)
printf(“Substring is found.”);
else
printf(“not found”);
return 0;
}
/* Return index of first match of itemPointer in listPointer. */
int find_substr(char *listPointer, char *itemPointer)
{
int t;
char *p, *p2;
for(t=0; listPointer[t]; t++) {
p = &listPointer[t];
p2 = itemPointer;
while(*p2 && *p2==*p) {
p++;
p2++;
}
if(!*p2) return t; /* 1st return */
}
return -1; /* 2nd return */
}