判断一个字符串是另一个的子串

#include "stdio.h"
#include "string.h"
#include "malloc.h"

/*--------------------------------------------------------
函数名:		int str_zi(char *,char *)
函数功能:	判断一个字符串是另一个字符串的子串
作者:		HES
输入参数:	父串,子串
输出参数:	1---0
--------------------------------------------------------*/

int str_zi(char *str1,char *str2)
{
	int len1=strlen(str1);		//父串长度
	int len2=strlen(str2);		//子串长度
	int i;
	char * p;					

	if(len1


上面这个递归版,在pc机上面可以正常使用,但是在单片机里面就有可能栈溢出,下面是轮询版,可以在单片机正常运行

#include
#include

/*--------------------------------------------------------
函数名:		int checkchild(char *,char *)
函数功能:	判断一个字符串是另一个字符串的子串
作者:		JUAN
输入参数:	子父串
输出参数:	1---0
--------------------------------------------------------*/

int checkchild(char *a,char *b)
{
        int i,j;
        int m,n,flag;

        m=strlen(b);
        n=strlen(a);
	if(m	
        for(i=0;i<=m-n;i++)
        {
                flag=1;
                for(j=0;j




你可能感兴趣的:(C/C++,Linux_C/C++)