1. 编程学习网 > 编程教程 > C语言教程 > C语言库函数-strstr()

C语言库函数-strstr()

C语言标准库 -

C语言库函数 char *strstr(const char *haystack, const char *needle) 在字符串 haystack 中查找第一次出现字符串 needle 的位置,不包含终止符 '\0'。

声明

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

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

参数

  • haystack -- 要被检索的 C 字符串。
  • needle -- 在 haystack 字符串内要搜索的小字符串。

返回值

该函数返回在 haystack 中第一次出现 needle 字符串的位置,如果未找到则返回 null。

实例

下面的实例演示了 strstr() 函数的用法。

实例

#include <stdio.h>#include <string.h> int main(){ const char haystack[20] = "itjxcom"; const char needle[10] = "itjx"; char *ret; ret = strstr(haystack, needle); printf("子字符串是: %s\n", ret); return(0); }

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

子字符串是: itjxcom

C语言标准库 -

本文由IT教学网整理发布,转载请注明出处:http://www.clang.cc//jiaocheng/cyuyan/1403.html

联系我们

在线咨询:点击这里给我发消息

咨询电话:400-998-2681

工作时间:7*24小时无休