is this the standard code for strstr i made????
char* fstrset(char *s,char *t)
{
int b, i=0,j=0;
while(*(s+i)!='\0')
{
if(*(t+j)=='\0')
break;
else if(*(s+i)==*(t+j))
{
i++;j++;b=1;
}
else
{ i++;b=0;j=0;
}
}
if(b==0)
return((char*)NULL);
else if(b==1)
return(s+i-j);
}
This is all the standard has to say about it:
So, it looks like you're missing
const
qualifiers on arguments.As for style, note that
*(ptr+index)
can be replaced byptr[index]
, andsize_t
is the best type to use for indexing a pointer.As for being a common way to implement it, compare with GCC's code:
Your code is buggy. Given:
fstrset(haystack, needle)
returns incorrectly returnsNULL
.