CCNProjects
Technical User
Hello and happy new year.
I am looking for strstr() code.
Every code I found had a bug!
could you help either find the bug or just post the correct one.
thanks a lot.
char *strstr2(char string1[], char string2[])
{//
char *start, *p1, *p2;
for(start = &string1[0]; *start != '\0'; start++)
{ /* for each position in input string... */
p1 = string2; /* prepare to check for pattern string there */
p2 = start;
while(*p1 != '\0')
{
if(*p1 != *p2) /* characters differ */
break;
p1++;
p2++;
}
if(*p1 == '\0') /* found match */
return start;
}
return NULL;
}
I am looking for strstr() code.
Every code I found had a bug!
could you help either find the bug or just post the correct one.
thanks a lot.
char *strstr2(char string1[], char string2[])
{//
char *start, *p1, *p2;
for(start = &string1[0]; *start != '\0'; start++)
{ /* for each position in input string... */
p1 = string2; /* prepare to check for pattern string there */
p2 = start;
while(*p1 != '\0')
{
if(*p1 != *p2) /* characters differ */
break;
p1++;
p2++;
}
if(*p1 == '\0') /* found match */
return start;
}
return NULL;
}