charmatch.cpp

来自「基于正则表达式的字符串匹配」· C++ 代码 · 共 41 行

CPP
41
字号
// charmatch.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include "stdlib.h"
#include <iostream>

using namespace std;

int match(char main[], char sub[])
{
int i(0),j(0);

while(main[i+j]!='\0'&&sub[j]!='\0')
{
if(main[i+j]==sub[j])j++;
else
{
i++;j=0;
}
}

if(sub[j]=='\0')
return i;

else 
return -1;


}

int _tmain(int argc, _TCHAR* argv[])
{
	char *p="abcdefghij";
	char *p1="cde";
	cout<<match(p,p1)<<endl;
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?