【FROM MSDN && 百科】

原型:char *strstr(const char *str1, const char *str2);

#include<string.h>

找出str2字符串在str1字符串中第一次出现的位置(不包括str2的串结束符)。返回该位置的指针,如找不到,返回空指针。

Returns a pointer to the first occurrence of strSearch in str, or NULL if strSearch does not appear in str. If strSearch points to a string of zero length, the function returns str.

DEMO: mystrstr

    1. //#define FIRST_DEMO
    2. #define SECOND_DEMO
    3. #ifdef FIRST_DEMO
    4. #include <stdio.h>
    5. #include <conio.h>
    6. #include <string.h>
    7. int main(void)
    8. {
    9. char *s="Golden Global View";
    10. char *l="lob";
    11. char *p;
    12. system("cls");
    13. p=strstr(s,l);
    14. if (p!=NULL)
    15. {
    16. printf("%s\n",p);
    17. }
    18. else
    19. {
    20. printf("Not Found!\n");
    21. }
    22. getch();
    23. return 0;
    24. }
    25. #elif defined SECOND_DEMO
    26. /*从字串” string1 onexxx string2 oneyyy”中寻找”yyy”*/
    27. #include <stdio.h>
    28. #include <conio.h>
    29. #include <string.h>
    30. int main(void)
    31. {
    32. char *s="string1 onexxx string2 oneyyy";
    33. char *p;
    34. p=strstr(s,"string2");
    35. printf("%s\n",p);
    36. if (p==NULL)
    37. {
    38. printf("Not Found!\n");
    39. }
    40. p=strstr(p,"one");
    41. printf("%s\n",p);
    42. if (p==NULL)
    43. {
    44. printf("Not Found!\n");
    45. }
    46. p+=strlen("one");
    47. printf("%s\n",p);
    48. getch();
    49. return 0;
    50. }
    51. #endif

char *strstr(const char *str1, const char *str2);的更多相关文章

  1. [Link 2005]vs2015 LNK2005 "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl printR(class std::basic_ostream<char,struct std::char_traits<char> > &,class QueryResult const &)" (?

      vs2015 LNK2005 "class std::basic_ostream<char,struct std::char_traits<char> > &am ...

  2. char 转wchar_t 及wchar_t转char

    利用WideCharToMultiByte函数来转换,该函数映射一个unicode字符串到一个多字节字符串.通常适合于window平台上使用. #include <tchar.h> #in ...

  3. const参数,const返回值与const函数

    在C++程序中,经常用const 来限制对一个对象的操作,例如,将一个变量定义为const 的: const  int  n=3; 则这个变量的值不能被修改,即不能对变量赋值. const 这个关键字 ...

  4. C语言中判断字符串str1是否以str2开始或结束

    #include <stdlib.h> #include <string.h> #include <stdio.h> /**判断str1是否以str2开头 * 如果 ...

  5. c++中的const参数,const变量,const指针,const对象,以及const成员函数

    const 是constant 的缩写,“恒定不变”的意思.被const 修饰的东西都受到强制保护,可以预防意外的变动,能提高程序的健壮性.所以很多C++程序设计书籍建议:“Use const whe ...

  6. const和非const函数重载

    成员函数后面加const,表示在该函数中不能对类的数据成员进行改变,比如下面的代码: #include <stdio.h> class A { private: mutable int a ...

  7. C/C++对bool operator < (const p &a)const的认识,运算符重载详解(杂谈)

    下面来进行这段代码的分析: struct node {  //定义一个结构体node(节点)    int x;    int y;    int len;   //node中有3个成员变量x,y,l ...

  8. C++中加const与不加const的区别

    “常量”与“只读变量”的区别. 常量肯定是只读的,例如5, "abc",等,肯定是只读的,因为常量是被编译器放在内存中的只读区域,当然也就不能够去修改它. “只读变量”则是在内存中 ...

  9. 12.C++-构造函数与析构函数调用顺序,const成员函数,const对象

    单个对象创建时,构造函数的调用顺序 1.首先判断该对象的类是否拥有父类,若有则先调用父类的构造函数 2.判断该对象的成员是否是其它类的成员,若是则调用成员变量的构造函数(调用顺序和声明顺序相同) 3. ...

随机推荐

  1. day26<网络编程>

    网络编程(网络编程概述) 网络编程(网络编程三要素之IP概述) 网络编程(网络编程三要素之端口号概述) 网络编程(网络编程三要素协议) 网络编程(Socket通信原理图解) 网络编程(UDP传输) 网 ...

  2. UE4射线的碰撞与绘制

    http://blog.csdn.net/qq992817263/article/details/51800657 //起点 终点 FHitResult RayGetHitResult(FVector ...

  3. 导入google地图

    一直报地图页面的 java.lang.incompatibleclasschangeerror 想来想去,应该是包不兼容的原因,原本以为,在 build.gradle 里面 compileSdkVer ...

  4. jQuery的无new构建

    正常面向对象的写法: var cJquery = function(){ //构造函数体 }; cJquery.prototype = { name : function(alert("ch ...

  5. mybatis的<choose>和<when>、<otherwise>标签

    SELECT<choose> <when test='timeType=="yy"'> TO_CHAR(REPORT_TIME,'yyyy') </w ...

  6. javascript飞机大战-----007爆炸效果

    要检验什么时候碰撞,我们必须了解什么时候不相撞.以上四种情况是不相撞的时候 首先在引擎里面写好什么时候碰撞什么时候不碰撞 /* 游戏引擎 */ var Engine = { //刚开始的游戏状态 ga ...

  7. Shell--基础知识

    变量的定义: a=1 b=hello c="hello world !" d='hello "反启" !' e=`ls`  (注意:这是反引号) 备注:=号左右 ...

  8. 浙江工业大学校赛 XiaoWei的战斗力

    XiaoWei的战斗力 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  9. 详解spring boot mybatis全注解化

    本文重点介绍spring boot mybatis 注解化的实例代码 1.pom.xml //引入mybatis <dependency> <groupId>org.mybat ...

  10. spring boot 打包方式 spring boot 整合mybaits REST services

    <build> <sourceDirectory>src/main/java</sourceDirectory> <plugins> <plugi ...