目录

char *strstr(const char *haystack, const char *needle)

描述 (Description)

C库函数char *strstr(const char *haystack, const char *needle)函数查找字符串haystack第一次出现的子串needle 。 终止'\ 0'字符不进行比较。

声明 (Declaration)

以下是strstr()函数的声明。

char *strstr(const char *haystack, const char *needle)

参数 (Parameters)

  • haystack - 这是要扫描的主要C字符串。

  • needle - 这是用in-haystack字符串搜索的小字符串。

返回值 (Return Value)

此函数返回指向在haystack中指定的任何整个字符序列中的第一个出现的指针,如果在haystack中不存在该序列,则返回空指针。

例子 (Example)

以下示例显示了strstr()函数的用法。

#include <stdio.h>
#include <string.h>
int main () {
   const char haystack[20] = "IoWiki";
   const char needle[10] = "Point";
   char *ret;
   ret = strstr(haystack, needle);
   printf("The substring is: %s\n", ret);
   return(0);
}

让我们编译并运行上面的程序,它将产生以下结果 -

The substring is: Point
↑回到顶部↑
WIKI教程 @2018