blob: 4300f24fb1fb48ff16203ad4b40debd7bdfcb9a8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#include <string.h>
char *strstr(const char *s1, const char *s2) {
// If s2 points to a string with zero length, the function shall return s1.
if ('\0' == *s2) {
return (char *)s1;
}
for (; *s1; s1++) {
const char *t1 = s1;
const char *t2 = s2;
int is_dif = 0;
for (; *t2 && *t1; t1++, t2++) {
if (*t2 != *t1) {
is_dif = 1;
break;
}
}
if (!is_dif) {
return (char *)s1;
}
}
return NULL;
}
|