#include <string.h>
char *strstr(const char *haystack, const char *needle);

功能:在字符串haystack中查找字符串needle出现的位置
参数:

  • haystack:源字符串首地址
  • needle:匹配字符串首地址

返回值:

  • 成功:返回第一次出现的needle地址
  • 失败:NULL

案例

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>

int main(void)
{
    char ch[] = "hello world";
    char str[] = "llo";
    // 查找字符串
    char* p = strstr(ch, str);
    // 记录出现位置
    printf("%s\n", p);

    return 0;
}
strstr

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-29
  • 2021-09-07
  • 2022-01-15
  • 2022-12-23
  • 2021-08-21
  • 2022-12-23
猜你喜欢
  • 2021-05-13
  • 2021-07-16
  • 2021-08-04
  • 2022-01-21
  • 2022-12-23
  • 2021-12-24
相关资源
相似解决方案