Hi, please don't blame me for reinventing the wheel, I was bored and had nothing to do, so I thought: what would I write?
And apparently this code is the result :P
strstr implementation from scratch
/**
@author: Mathias Van Malderen (tux4life)
*/
const char *astrstr(const char *s1, const char *s2)
{
for(; *s1; s1++)
{
for(int i=0; *s1 && *s2; s1++, s2++, i++)
{
if(!(*s1==*s2))
{
s1-=i;
s2-=i;
break;
} else if(!(*(s2+1))) {
return s1-i;
}
}
}
return 0;
}
tux4life 2,072 Postaholic
IUnknown 0 Newbie Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.