C标准库源代码

源代码在线查看: strstr.c

软件大小: 1707 K
上传用户: yl810406
关键词: 标准库 源代码
下载地址: 免注册下载 普通下载 VIP

相关代码

				/***
				*strstr.c - search for one string inside another
				*
				*       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
				*
				*Purpose:
				*       defines strstr() - search for one string inside another
				*
				*******************************************************************************/
				
				#include 
				#include 
				
				/***
				*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);
				
				}
							

相关资源