C库函数strstr分析

2022-10-12,,

c标准库<string.h>

函数声明:
char* strstr(char* const _string, char const* const _substring)

返回值:
substring在string中第一次出现的位置,直到末尾,不包括\0

示例:

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

int main()
{

    char a[10] = "hello";
    char b[5] = "ll";
    char* ret = strstr(a, b);

    printf("%s, %p\n%p\n%p", ret, ret, &a[2], &b[0]);
    return 0;
}


//结果:
/*------------
value of ret is: llo
addr of ret is: 00eff73a
addr of a[2] is:00eff73a
addr of b[0] is: 00eff728
------------*/

《C库函数strstr分析.doc》

下载本文的Word格式文档,以方便收藏与打印。