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. ...
随机推荐
- JBPM4.4_jBPM4.4的流程定义语言(设计流程)
1. jBPM4.4的流程定义语言(设计流程) 1.1. process(流程) 是.jpdl.xml的根元素,可以指定的属性有: 属性名 作用说明 name 流程定义的名称,用于显示. key 流程 ...
- 详解Integer.toString(int i)方法和String.valueOf(int i)方法
通过查看String类的源码: public static String valueOf(int i) { return Integer.toString(i); } 我们可以看到,String.va ...
- jquery获取父级元素、子级元素、兄弟元素的方法
jQuery.parent(expr) 找父亲节点,可以传入expr进行过滤,比如$("span").parent()或者$("span").parent(&q ...
- WIN10 X64下通过TLS实现反调试
目录(?)[-] TLS技术简介 1 TLS回调函数 2 TLS的数据结构 具体实现及原理 1 VS2015 X64 release下的demo 2 回调函数的具体实现 21 使用IsDebugger ...
- String.Join重载String.Join 方法 (String, String[], Int32, Int32)
https://msdn.microsoft.com/zh-cn/library/tk0xe5h0 String.Join 方法 (String, String[], Int32, Int32) 官方 ...
- 《转》python学习(6)序列类型-字符串
转自 http://www.cnblogs.com/BeginMan/archive/2013/06/08/3125502.html 二.序列类型 包含字符串.列表.元祖.模式都一样,举一反三即可.如 ...
- poj_3580 伸展树
自己伸展树做的第一个题 poj 3580 supermemo. 题目大意 对一个数组进行维护,包含如下几个操作: ADD x, y, d 在 A[x]--A[y] 中的每个数都增加d REVERSE ...
- js基础---->js中的消息框
可以在JavaScript 中创建三种消息框:警告框.确认框.提示框.今天我们就这几个框做一个介绍.我们笑着说再见,却深知再见遥遥无期. javascript消息框 一.警告框:警告框经常用于确保用户 ...
- c++ 利用new动态的定义二维数组
#include <iostream> using namespace std; int main() { , col = ; // key code: 申请空间 int **edge = ...
- Ubuntu远程登录服务器--ssh的安装和配置
ssh是一种安全协议,主要用于给远程登录会话数据进行加密,保证数据传输的安全. 安装ssh sudo apt-get update sudo apt-get install openssh-serve ...