C++中strstr函数的实现方法总结
函数说明:
包含文件:string.h
函数名: strstr
函数原型:extern char *strstr(char *str1, char *str2);
功能:从字符串str1中查找是否有字符串str2, 如果有,从str1中的str2位置起,返回str1的指针,如果没有,返回null。
返回值:返回该位置的指针,如找不到,返回空指针。
方法一:
#include <iostream>
#include <assert.h>
using namespace std;
char* My_strstr(char *src,char *substr)
{
assert(src != NULL && substr != NULL);
unsigned int size = strlen(src);
for(int i = 0; i < size; ++i,++src)
{
char *p = src;
for(char *q = substr;;p++,q++)
{
if(*q == '