PROWAREtech
C/C++: strstr Procedure
Find a substring in an ASCII c-string.
Returns NULL (0) pointer when substring is not found in string, otherwise, returns pointer in str
where substr
was found.
char* strstr(char *str, char *substr)
{
if(!*substr)
return str;
for(char* a, *b = substr; *str; str++)
{
if (*str != *b)
continue;
a = str;
while (1)
{
if (!*b)
return str;
if (*a++ != *b++)
break;
}
b = substr;
}
return 0;
}
Comment