char *strstr(const char *s1, const char *s2) { int n; if (*s2) { while (*s1) { for (n = 0; *(s1 + n) == *(s2 + n); n++) { if (!*(s2 + n + 1)) return (char *) s1; } s1++; } return NULL; } else return (char *)s1; }
v2
char *strstr(const char *s1, const char *s2) { int len2; if (!(len2 = strlen(s2))) return (char *) s1; for (; *s1; ++s1) { if (*s1 == *s2 && strncmp(s1, s2, len2) == 0) return (char *) s1; } return NULL; }