落絮飞雁

顺流而下,把梦做完

strstr()函数:返回字符串中首次出现子串的地址

头文件:#include <string.h>

strstr()函数用来检索子串在字符串中首次出现的位置,其原型为:
char *strstr( char *str, char * substr );

【参数说明】str为要检索的字符串,substr为要检索的子串。

【返回值】返回字符串str中第一次出现子串substr的地址;如果没有检索到子串,则返回NULL。

【函数示例】strstr()函数的使用。

例:

 

#include
#include
int main(){
    // 也可以改成 char str[] = "http://see.xidian.edu.cn/cpp/u/xitong/";
    char *str = "http://see.xidian.edu.cn/cpp/u/xitong/";
    char *substr = "see";
    char *s = strstr(str, substr);
    printf("%sn", s);
    return 0;
}

原文标题:strstr()函数:返回字符串中首次出现子串的地址|落絮飞雁的个人网站
原文链接:https://www.luoxufeiyan.com/2014/10/31/strstr%e5%87%bd%e6%95%b0%ef%bc%9a%e8%bf%94%e5%9b%9e%e5%ad%97%e7%ac%a6%e4%b8%b2%e4%b8%ad%e9%a6%96%e6%ac%a1%e5%87%ba%e7%8e%b0%e5%ad%90%e4%b8%b2%e7%9a%84%e5%9c%b0%e5%9d%80/
授权协议:创作共用 署名-非商业性使用 2.5 中国大陆
除注明外,本站文章均为原创;转载时请保留上述链接。