【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. layui时间,table,大图查看,弹出框,获取音频长度,文件上传

    1.引入: <link href="../../Scripts/layui-v2.3.0/css/layui.css" rel="stylesheet" ...

  2. POJ 1160 Post Office(区间DP)

    Description There is a straight highway with villages alongside the highway. The highway is represen ...

  3. THINKPHP include 标签动态加载文件

    有时候需要在框架中动态的加载一些文件,文件名不确定,有控制器获取得到,想在模板中使用变量的形式进行加载,本以为这样写可以 结果不行 <include file="User/{$my_t ...

  4. H5 readfile 多图片预览

    /** * 多图片前端预览 * @author Tiac */ function preView(_this, offset){ let max_nums = 10;//单位 s let max_si ...

  5. 【RF库测试】关键字get time

    *** Test Cases ***Timestamp ${time} GET TIME ${secs} GET TIME epoch ${year} GET TIME return year ${y ...

  6. Android中Bitmap和Drawable详解

    一.相关概念 1.Drawable就是一个可画的对象,其可能是一张位图(BitmapDrawable),也可能是一个图形(ShapeDrawable),还有可能是一个图层(LayerDrawable) ...

  7. Vitamio与FFmpeg、LGPL、GPL的关系

    转自:http://sun.sanniang.me/2014/04/26/the-relationship-vitamio-with-ffmepg-lgp-gpl Vitamio 使用了 FFmpeg ...

  8. Oracle分页查询sql语句

    1. select * from ( select  t.*, rownum RN from TABLE_NAME  t ) where RN > 0 and RN <= 15 2. se ...

  9. Set集合遍历方式

    for(String str : set) { System.out.println(str); } for (Iterator iter = set.iterator(); iter.hasNext ...

  10. PHP中new static()与new self()的区别异同

    self - 就是这个类,是代码段里面的这个类. static - PHP 5.3加进来的只得是当前这个类,有点像$this的意思,从堆内存中提取出来,访问的是当前实例化的那个类,那么 static ...