Suppose the length of haystack is n, the length of needle is k, then this algorithm is at worst O( (n-k)k ) in time.

Intuitively, we start from the first char of haystack, searching through the (n-k)th one, to look for any matches.

```
char *h, *n;
int i, j;
for( i = 0; i <= (int)strlen( haystack ) - (int)strlen( needle ); i++ ) {
h = haystack + i;
n = needle;
j = 0;
while( j < strlen( needle ) && *h++ == *n++ )
j++;
if( j == strlen( needle ) )
return i;
}
return -1;
}
```