strstr函数
描述
C 库函数 char *strstr(const char *haystack, const char *needle) 在字符串 haystack 中查找第一次出现字符串 needle 的位置,不包含终止符 ‘\0’。
声明
char *strstr(const char *haystack, const char *needle)
参数
haystack – 要被检索的 C 字符串。
needle – 在 haystack 字符串内要搜索的小字符串。
返回值
该函数返回在 haystack 中第一次出现 needle 字符串的位置,如果未找到则返回 null。
使用
int main()
{
char *p1 = "abcdefgddddddddrrrr";
char *p2 = "ddddd";
char* ret = strstr(p1, p2);
if (ret == NULL)
{
printf("不存在");
}
else
{
printf("%s\n", ret);
}
return 0;