C语言strstr函数源代码
时间: 2023-09-05 20:14:00 浏览: 175
Sure, I can help you with that!
Here's the source code for the C language strstr() function:
```c
char *strstr(const char *haystack, const char *needle) {
char *p = (char *) haystack;
char *q = (char *) needle;
while (*p) {
if (*p == *q) {
// found the first character of the needle
size_t len = strlen(q);
if (strncmp(p, q, len) == 0) {
// found the complete needle in haystack
return p;
}
}
// didn't find the complete needle yet, keep looking
p++;
}
// couldn't find the needle in haystack
return NULL;
}
```
Is there anything else I can help you with today?
阅读全文