25 Years of Programming
An open source source for C, C++, OWL, BASIC, MDB, XLS, DOT, and more...
Home   Projects   Up   Sitemap   Search   Blog   Forum+Chat   About Us   Privacy   Terms of Use   Feedback   FAQ   Images   Services   Payments   Humor   Music  

String search function in DeSmet C

strindex() simulates the BASICA INSTR function.

If the search string is found in its entirety in the target string, it returns a pointer to the first character of the match in the target string, else it returns null.

/* ===========================================================*/
/* STRING SEARCH FN */
/* ===========================================================*/
/* ----------------------------------------------------------------------- */
/*  STRINDEX()    10-12-93  */
/*	Copyright (C)1993 Steven Whitney. Published under the */
/*	GNU GPL (General Public License) Version 3, with ABSOLUTELY NO WARRANTY. */
/*	Initially published by http://25yearsofprogramming.com. */
/*	strindex(compare,search) simulates BASICA INSTR function.  If *search */
/*	is found in its entirety in *compare, then the function returns a */
/*	pointer to the first character match occurance in *compare. */
/*	Else it returns null.     */
/* ----------------------------------------------------------------------- */
char *strindex(compare,search)
char *compare, *search;
{
char *index();
int slen;

slen = strlen(search);
while(compare = index(compare,search[0]))	/* only test at each search[0] */
{
	if(!strncmp(compare,search,slen))
		return(compare);
	compare++;				/* increment 1 char past previous index */
}
return(0);
}

 

 

Valid HTML 4.01 Transitional
Yahoo! Search
Search the web Search this site
Valid CSS