www.pudn.com > strseach_location.rar > strseach_location.cpp, change:2010-12-22,size:1380b


// strseach_location.cpp : Defines the entry point for the console application. 
// 
 
#include "stdafx.h" 
#include "stdio.h" 
#include "stdlib.h" 
 
 
 
// by bill.zhang 201012220041 
int strseach_location(const char *src,int srclen,const char *des,int deslen) 
{ 
	int tempvar=0,tempcounter=0,tempdeslen=deslen; 
	char *tempbuf; 
	tempbuf=(char *)malloc(srclen); 
	if (srclen>=deslen) 
	{ 
		for (tempvar=0;tempvar<srclen;tempvar++) 
		{ 
			if(src[tempvar]==des[0]) 
			{ 
				if (srclen-tempvar>=deslen) 
				{ 
					memcpy(tempbuf,&src[tempvar],srclen-tempvar); 
					while (tempdeslen--) 
					{ 
						if (tempbuf[tempcounter]==des[tempcounter]) 
						{ 
							tempcounter++; 
						} 
						else 
						{ 
							break ; 
						} 
					} 
					if (tempcounter==deslen) 
					{ 
						return tempvar; 
					} 
					tempdeslen=deslen; 
					tempcounter=0; 
				} 
			} 
		} 
	} 
	else  
	{ 
		return -1; 
	} 
	return -1; 
} 
 
char app1[]={0,1,2,2,3,4,5,0,2,3,44,55,33,22,5,5,4,7,3,44}; 
 
char app2[]={0,2,3,44,55}; 
 
 
int _tmain(int argc, _TCHAR* argv[]) 
{ 
	int testvar=0; 
	testvar = strseach_location("hhhehlohdfafgghhhhdshelloworldafdsfkhhelloheadkjfskdjfkasdjlfk",sizeof("hhhehlohdfafgghhhhdshelloworldafdsfkhhelloheadkjfskdjfkasdjlfk")-1,"helloworld",sizeof("helloworld")-1); 
	testvar = strseach_location(app1,20,app2,5); 
	system("pause"); 
	return 0; 
}