您的位置:首页 > 其它

strstr查找字符串, strch查找字符 (在字符串中) [Microsoft Corporation]

2011-08-26 10:57 211 查看
/***
*char *strchr(string, c) - search a string for a character
*
*Purpose:
*       Searches a string for a given character, which may be the
*       null character '\0'.
*
*Entry:
*       char *string - string to search in
*       char c - character to search for
*
*Exit:
*       returns pointer to the first occurence of c in string
*       returns NULL if c does not occur in string
*
*Exceptions:
*
*******************************************************************************/

char * __cdecl strchr (
const char * string,
int ch
)
{
while (*string && *string != (char)ch)
string++;

if (*string == (char)ch)
return((char *)string);
return(NULL);
}
/****char *strstr(string1, string2) - search for string2 in string1**Purpose:*       finds the first occurrence of string2 in string1**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 strstr (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 && !(*s1-*s2) )s1++, s2++;if (!*s2)return(cp);cp++;}return(NULL);}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: