【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. POJ 1273 Drainage Ditches (网络最大流)

    http://poj.org/problem? id=1273 Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Sub ...

  2. Effective C++ Item 18 Make interfaces easy to use correctly and hard to use incorrectly

    1. A good API will provide easy to use interfaces but also provide hard to miss-use interfaces. Usua ...

  3. ios开发之--判断奇偶数

    ==) {//如果是偶数 }else{//如果是奇数 } 记录下!

  4. Path类和File类的应用

    今天是我学习C#基础的第13天,可以说马上就要结束这个基础课程,感觉学习的理论性的我不能说全部掌握了,我只想说在思路上面的语法以及用法我应该基本掌握了,感觉效果不错,不得不说,要想在一种语言上面有大的 ...

  5. lua中类的实现原理和实践

    一.基础概念  Lua 本身是函数式的语言,但借助 metatable (元表)这个强大的工具,Lua 实现操作符重载易如反掌.. 下文将详细的解释在Lua中实现类的原理,涉及到的细节点将拆分出来讲, ...

  6. Android开发 Android Studio2.0 教程从入门到精通Windows版 - 入门篇

    第一篇 介绍了Android Studio开发环境以及Genymotion虚拟机安装方法,本节将给大家介绍如何使用Android Studio开发应用. 开发第一应用 可以开发属于自己的应用,是否有点 ...

  7. android基础---->摄像头与相册的调用

    很多应用程序都可能会使用到调用摄像头拍照和从相册选取图片的功能,今天我们开始android中摄像头与相册调用的学习. 目录导航 调用摄像头拍照 从相册中选择照片 友情链接 调用摄像头拍照 大致流程:调 ...

  8. 【Android M】获取屏幕锁定的相关信息:“无”,“滑动”,“PIN码”,"图案","密码"

    ENV: Android M 6.0.1 import android.os.UserHandle;         import com.android.internal.widget.LockPa ...

  9. 【BZOJ2595】[Wc2008]游览计划 斯坦纳树

    [BZOJ2595][Wc2008]游览计划 Description Input 第一行有两个整数,N和 M,描述方块的数目. 接下来 N行, 每行有 M 个非负整数, 如果该整数为 0, 则该方块为 ...

  10. 电力项目十七--数据字典首页JS添加和删除表格

    知识点:jQuery是一个JavaScript函数库. JS代码: function insertRows(){ //获取表格对象 var tb1 = $("#dictTbl"); ...