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. ...
随机推荐
- CUGBACM Codeforces Tranning 1 题解
链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=61581#overview 描写叙述:非常老的CF题,题不错,拿来训练正好. 做的时 ...
- vertica时间计算SQL语句实例:统计一天内登录的用户
SQL语句实例: select count(id) as num from public.user where cast((CURRENT_TIMESTAMP-login_timed) day as ...
- 工作流JBPM_day01:2-HelloWorld
工作流JBPM_day01:2-HelloWorld 新建一个java工程Jbpm4.4 拷贝helloworld.jpdl.xml和helloworld.png文件出来压缩成helloworld.z ...
- HTML&CSS精选笔记_CSS高级技巧
CSS高级技巧 CSS精灵技术 需求分析 CSS精灵是一种处理网页背景图像的方式.它将一个页面涉及到的所有零星背景图像都集中到一张大图中去,然后将大图应用于网页,这样,当用户访问该页面时,只需向服务发 ...
- Ext3.4--Gridpanel
Ext.onReady(function () { var sm = new Ext.grid.RowSelectionModel({singleSelect:true})//设置单选 //var s ...
- VC++第三方库配置-OpenSpirit 4.2.0 二次开发
在VS中右击项目,点击属性 1.配置属性--常规--输出目录:Windows\VS2010\debug\ 2.配置属性--常规--中间目录:Windows\VS2010\debug\ 3.配置属性-- ...
- Nginx(一)-- 初体验
1.概念 Nginx ("engine x") 是一个高性能的 HTTP 和反向代理服务器,也是一个 IMAP/POP3/SMTP 服务器. Nginx提供基本http服务,可以作 ...
- EF更新的时候出错
错误提示: 存储区更新.插入或删除语句影响到了意外的行数(0).实体在加载后可能被修改或删除.刷新 ObjectStateManager 项. 说明: 执行当前 Web 请求期间,出现未经处理的异常. ...
- HTML5中新的结构元素
HTML5中新的结构元素 1. HTML5初始文件 1.1.doctype 在之前,doctype的声明是这样的: "http://www.w3. org/TR/html4/strict.d ...
- java高级---->Thread之Condition的使用
Condition 将 Object 监视器方法(wait.notify 和 notifyAll)分解成截然不同的对象,以便通过将这些对象与任意 Lock 实现组合使用,为每个对象提供多个等待 set ...