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. ...
随机推荐
- Java精选笔记_Java编程基础
Java的基本语法 Java代码的基本格式 修饰符 class 类名 { 程序代码 } 一个Java源文件只定义一个类,不同的类使用不同的源文件定义:将每个源文件中单独定义的类都定义成public ...
- ionic ui框架及creator使用帮助
UI框架使用方法:http://ionicframework.com/docs/api/ PS:路由之类的其他js代码示例建议用 官方的app 生成器弄一个简单的页面,然后下载回来看 https:// ...
- [转载]2014年10月26完美世界校招两道java题
public class VolitileTest { volatile static int count=0; public static void main(String args[]){ for ...
- Dubbo(二) -- Simple Monitor
一.简介 dubbo-monitor-simple是dubbo提供的简单监控中心,可以用来显示接口暴露,注册情况,也可以看接口的调用明细,调用时间等. Simple Monitor挂掉不会影响到Con ...
- lodash(一)数组
前言: lodash是一个具有一致接口.模块化.高性能等特性的JavaScript工具库(官网地址:http://lodashjs.com/docs/#_differencearray-values) ...
- git Xcode
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://2009315319.blog.51cto.com/701759/1158515 ...
- poj_1475 BFS+BFS
题目大意 推箱子游戏的基本玩法,求将箱子推到目的地的推动次数最少(并不是人移动总次数)的人移动路径. 题目分析 求最短路径的搜索问题,使用BFS.注意题目求的是 推动次数最少,因此将箱子移动作为状态, ...
- Docker源码分析(八):Docker Container网络(下)
1.Docker Client配置容器网络模式 Docker目前支持4种网络模式,分别是bridge.host.container.none,Docker开发者可以根据自己的需求来确定最适合自己应用场 ...
- 图论之最短路径(3)队列优化的Bellman-Ford算法(SPFA算法)
在Bellman-Ford算法中 我们可以看到大量的优化空间:如果一个点的最短路径已经确定了,那么它就不会再改变,因此不需要再处理.换句话说:我们每次只对最短路径改变了的顶点的所有出边进行操作 使用一 ...
- 收集的可以下载css3字体图标的网站
http://icomoon.io/app/ 可以选择跟简单调整图标打包成css3 字体下载, http://www.flaticon.com/categories/weapons