char *strstr(const char *str1, const char *str2);
【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
- //#define FIRST_DEMO
- #define SECOND_DEMO
- #ifdef FIRST_DEMO
- #include <stdio.h>
- #include <conio.h>
- #include <string.h>
- int main(void)
- {
- char *s="Golden Global View";
- char *l="lob";
- char *p;
- system("cls");
- p=strstr(s,l);
- if (p!=NULL)
- {
- printf("%s\n",p);
- }
- else
- {
- printf("Not Found!\n");
- }
- getch();
- return 0;
- }
- #elif defined SECOND_DEMO
- /*从字串” string1 onexxx string2 oneyyy”中寻找”yyy”*/
- #include <stdio.h>
- #include <conio.h>
- #include <string.h>
- int main(void)
- {
- char *s="string1 onexxx string2 oneyyy";
- char *p;
- p=strstr(s,"string2");
- printf("%s\n",p);
- if (p==NULL)
- {
- printf("Not Found!\n");
- }
- p=strstr(p,"one");
- printf("%s\n",p);
- if (p==NULL)
- {
- printf("Not Found!\n");
- }
- p+=strlen("one");
- printf("%s\n",p);
- getch();
- return 0;
- }
- #endif
char *strstr(const char *str1, const char *str2);的更多相关文章
- [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 ...
- char 转wchar_t 及wchar_t转char
利用WideCharToMultiByte函数来转换,该函数映射一个unicode字符串到一个多字节字符串.通常适合于window平台上使用. #include <tchar.h> #in ...
- const参数,const返回值与const函数
在C++程序中,经常用const 来限制对一个对象的操作,例如,将一个变量定义为const 的: const int n=3; 则这个变量的值不能被修改,即不能对变量赋值. const 这个关键字 ...
- C语言中判断字符串str1是否以str2开始或结束
#include <stdlib.h> #include <string.h> #include <stdio.h> /**判断str1是否以str2开头 * 如果 ...
- c++中的const参数,const变量,const指针,const对象,以及const成员函数
const 是constant 的缩写,“恒定不变”的意思.被const 修饰的东西都受到强制保护,可以预防意外的变动,能提高程序的健壮性.所以很多C++程序设计书籍建议:“Use const whe ...
- const和非const函数重载
成员函数后面加const,表示在该函数中不能对类的数据成员进行改变,比如下面的代码: #include <stdio.h> class A { private: mutable int a ...
- C/C++对bool operator < (const p &a)const的认识,运算符重载详解(杂谈)
下面来进行这段代码的分析: struct node { //定义一个结构体node(节点) int x; int y; int len; //node中有3个成员变量x,y,l ...
- C++中加const与不加const的区别
“常量”与“只读变量”的区别. 常量肯定是只读的,例如5, "abc",等,肯定是只读的,因为常量是被编译器放在内存中的只读区域,当然也就不能够去修改它. “只读变量”则是在内存中 ...
- 12.C++-构造函数与析构函数调用顺序,const成员函数,const对象
单个对象创建时,构造函数的调用顺序 1.首先判断该对象的类是否拥有父类,若有则先调用父类的构造函数 2.判断该对象的成员是否是其它类的成员,若是则调用成员变量的构造函数(调用顺序和声明顺序相同) 3. ...
随机推荐
- Ubuntu12.04 Skype4.2 提示Skype can't connect,安装Skype4.3
最近几天Skype突然不能登录啦,以为是自己密码记错啦,重置啦一下密码,发现仍然提示”Skype can't connect“,我的版本是Ubuntu12.04 Skype4.2 尝试啦很多办法仍然不 ...
- Redis(四)-- 集群
一.Redis适合做企业级分布式缓存集群的条件 1.Redis内置哈希槽,有16384个哈希槽(0~16383),根据CRC16算法来确定这个集群中属于哪一个服务器来处理这个请求. 2.Redis提供 ...
- Linux curl 命令
curl is a tool to transfer data from or to a server, using one of the supported protocols ( http ,ht ...
- 如何在Oculus官网下载OculusSetup.exe(当前时间20170720)
踩着免费的蓝灯FQ登录了Oculus官网,找了半天找不到哪里下载OculusSetup.exe,最后在最下面的支持中心找到了..... https://www.oculus.com/
- Android 监听按钮的点击事件
onClick事件1.Button和ImageButton都拥有一个onClick事件 通过自身的.setOnClickListener(OnClickListener)方法添加点击事件2.所有的控件 ...
- c++ 引用底层实现
红色是我添加的,其他地方是原作者的. 主要是看了上面的这篇“从底层汇编理解 c++ 引用实现机制“的文章之后,觉得不错.就转了过来,同时,对文中的程序都在自己的机器上验证了一下. 使用的G++版本:g ...
- jquery类似方法的比较(一)
1. $(div + p) & $(div ~ p) & $(div p) & $(div > p) $(div + p)选择紧挨在div后面的P元素 $(div ~ p ...
- Eclipse '<>' operator is not allowed for source level below 1.7
'<>' operator is not allowed for source level below 1.7 解决方法:
- 【BZOJ2087】[Poi2010]Sheep 几何+DP
[BZOJ2087][Poi2010]Sheep Description Lyx的QQ牧场养了很多偶数个的羊,他是Vip,所以牧场是凸多边形(畸形).现在因为他开挂,受到了惩罚,系统要求他把牧场全部分 ...
- ListView之EmptyView
From:http://blog.csdn.net/xiangqiao123/article/details/17994099 继承ListActivity比较方便 最新开发一个应用程序,需要用到当L ...