C 库函数 - strstr()

Posted F

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C 库函数 - strstr()相关的知识,希望对你有一定的参考价值。

 

定义

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

参数

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

描述

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

 

例子

#include <stdio.h>
#include <string.h>


int main()
{
   const char haystack[20] = "RUNOOB";
   const char needle[10] = "NOOB";
   char *ret;

   ret = strstr(haystack, needle);

   printf("子字符串是: %s\n", ret);
   
   return(0);
}

输出

子字符串是: NOOB

 

 

参考:

https://www.runoob.com/cprogramming/c-function-strstr.html

以上是关于C 库函数 - strstr()的主要内容,如果未能解决你的问题,请参考以下文章