码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2014-12-06 11:22:05      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:style   http   io   ar   color   使用   sp   on   文件   

今天又学到了一个函数

头文件:#include <string.h>

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

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

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

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

#include<stdio.h>
#include<string.h>
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("%s\n", s);
    return 0;
}

运行结果:
see.xidian.edu.cn/cpp/u/xitong/

 

 

题1238用到这个函数。

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

标签:style   http   io   ar   color   使用   sp   on   文件   

原文地址:http://www.cnblogs.com/liudehao/p/4147983.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!