EmbLogic's Blog

for finding substring into the sentance u can get idea by this program…………

#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 */
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>