微軟c標準庫中字符串操做源代碼

位置:VC\crt\src (crt C RunTime library)c++

char * strcat(char * dst, const char * src)
{
 char * cp = dst;
 
 while(*cp)
 {
  cp++;  /* find end of dst */
 }
 
 while (*cp++ = *src++); /* Copy src to end of dst */
 
 return dst; /* return dst */
}spa

char * strcpy(char * dst, const char * src)
{
 char * cp = dst;
 
 while (*cp++ = *src++);  /* Copy src over dst */
 
 return dst;
}string

char * strchr(const char * string, int ch)
{
 while (*string && *string != (char)ch)
 {
  string++;
 }
 
 if (*string  == (char)ch;
  return (char *)string;
 
 return NULL;
}im

int strcmp(const char * src, const char * dst)
{
 int ret = 0;
 
 while (!(ret = *(unsigned char *)src - *(unsigned char *)dst) && *dst)
  ++src, ++dst;
  
 if ( ret < 0 )
   ret = -1 ;
  else if ( ret > 0 )
   ret = 1 ;while

  return( ret );
}co

size_t strlen(const char * str)
{
 const char * eos = str;
 
 while (*eos++);
 
 return (int)(eos - str - 1);
}library

char * strstr(const char * str1, const char * str2)
{
 char * cp = (char *)str1;
 char *s1, *s2;
 
 if (!*str2)
  return (char *)str1;
 
 while (*cp)
 {
  s1 = cp;
  s2 = str2;
  
  while (*s1 && *s2 && !(*s1-*s2))
   s1++, s2++;
  
  while (!*s2)
   return cp;
  
  cp++;
 }
 
 return NULL;
}return

相關文章
相關標籤/搜索