string系列之strcpy、strncpy、strcmp、strlen编程实现
2013-05-04 12:04
253 查看
string系列
char* strcpy( char *strDest, const char *strSrc )
{
assert((strDest != NULL) && (strSrc != NULL) );
char *address = strDest;
while((*strDest++ = * strSrc++) != ‘\0’ );
return address;
}
char*strncpy(char* strdest, const char* strsrc, int n)
{
assert((strdest != NULL) && (strsrc != NULL));
char* address = strdest;
while(n-- > 0)
*strdest++ = *strsrc++;
return address;
}
int strcmp(const char* str1, const char* str2)
{
assert((str1 != NULL) && (str2 != NULL);
int ret = 0;
while (!(ret = (unsigned char*)*str1 - (unsigned char*)*str2)&& (*str2))
{
str1++;
str2++;
}
if (ret > 0)
ret = 1;
else if (ret < 0)
ret = -1;
return ret;
}
int strlen(const char* str)
{
assert(str != NULL);
int len = 0;
while ('\0' != *str++)
len++;
return len;
}
char* strcpy( char *strDest, const char *strSrc )
{
assert((strDest != NULL) && (strSrc != NULL) );
char *address = strDest;
while((*strDest++ = * strSrc++) != ‘\0’ );
return address;
}
char*strncpy(char* strdest, const char* strsrc, int n)
{
assert((strdest != NULL) && (strsrc != NULL));
char* address = strdest;
while(n-- > 0)
*strdest++ = *strsrc++;
return address;
}
int strcmp(const char* str1, const char* str2)
{
assert((str1 != NULL) && (str2 != NULL);
int ret = 0;
while (!(ret = (unsigned char*)*str1 - (unsigned char*)*str2)&& (*str2))
{
str1++;
str2++;
}
if (ret > 0)
ret = 1;
else if (ret < 0)
ret = -1;
return ret;
}
int strlen(const char* str)
{
assert(str != NULL);
int len = 0;
while ('\0' != *str++)
len++;
return len;
}
相关文章推荐
- 实现strlen,strcpy,strcat,strcmp同功能的函数stringLength,stringCopy,stringCatch,stringCompare
- 自定义实现字符串处理函数 strlen strcmp strcpy strncpy strcat strncat strchr strstr
- strlen,strcpy,strncpy,strcmp,strcat,strstr的用法,函数原型及函数的实现
- 字符串库函数strlen,strcmp,strcpy,strncpy,strcat,strncat自定义实现
- strcpy,strncpy, strlen, strcmp strcat函数实现
- C语言中strlen、strcpy、strncpy、strcat、strnact、strcmp、memcpy函数的实现
- 几个常用函数的实现strcpy、 strncpy、 strncat 、 strcmp、 strlen
- strlen strcmp strcat strcpy strncpy strstr strchar函数的实现
- strlen,strcat,strcpy,strncpy,strcmp的具体实现
- 模拟实现strcmp,strncmp,strstr,strcat,strncat,strcpy,strncpy,strlen ,memcpy,memmove等函数
- strlen(),strcpy(),strncpy(),strcat(),strncat(),strcmp(),strncmp()等函数的实现
- 模拟实现strlen、strcpy、strncpy、strcat、strcmp
- 自己实现strcpy,strncpy,strncat,strcmp,strlen的功能
- C语言中strlen、strcpy、strncpy、strcat、strnact、strcmp、memcpy函数的实现
- 自定义实现字符串处理函数 strlen strcmp strcpy strncpy strcat strncat strchr strstr
- 模拟实现: strstr strcpy strlen strcat strcmp memcpy memmove
- [C语言]strcat strstr strcpy strcmp strlen 的实现与使用
- 字符串函数strcat, strcpy, strcmp, strlen实现模型
- strlen,strcpy,strcat,strcmp四个函数的原型,memcpy,memset的实现
- 字符串函数模拟实现之strcpy、strncpy、strcmp、strncmp、strcat、strncat