strstr函数

目录

函数介绍:

函数分析:

​使用案例:


函数介绍:

返回指向 str1 中第一次出现的 str2 的指针,如果 str2 不是 str1 的一部分,则返回一个空指针。
匹配过程不包括终止空字符,但它到此为止。

函数分析:

strstr函数_第1张图片 

使用案例:

#include 
#include 
int main ()
{
 char str[] ="This is a simple string";
 char * pch;
 pch = strstr (str,"simple");
 strncpy (pch,"sample",6);
 printf("%s\n", str);
 return 0;
} 

 上面代码中的pch正是拿到了进行strstr后的返回值,也就是字符串str中simple的首字符地址,而后使用了strncpy函数进行拷贝,将sample这六个字符拷贝到了原先simple所处的位置上,使得str字符串发生了改变。

strstr函数_第2张图片

你可能感兴趣的:(C语言,算法,c语言,指针,函数,字符串)