1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | /****stristr.c - search for one string inside another** Copyright (^_^) zhao4zhong1@163.com. All rights reserved.**Purpose:* defines stristr() - search for one string inside another********************************************************************************/#include <cruntime.h>#include <string.h>#include <ctype.h>/****char *stristr(string1, string2) - search for string2 in string1 without regard to case.**Purpose:* finds the first occurrence of string2 in string1 without regard to case.**Entry:* char *string1 - string to search in* char *string2 - string to search for**Exit:* returns a pointer to the first occurrence of string2 in* string1, or NULL if string2 does not occur in string1**Uses:**Exceptions:********************************************************************************/char * __cdecl stristr ( const char * str1, const char * str2 ){ char *cp = (char *) str1; char *s1, *s2; if ( !*str2 ) return((char *)str1); while (*cp) { s1 = cp; s2 = (char *) str2; while ( *s1 && *s2 && !(_tolower(*s1)-_tolower(*s2)) ) s1++, s2++; if (!*s2) return(cp); cp++; } return(NULL);} |
聯(lián)系客服