您的位置:首页 > 编程语言 > C语言/C++

C语言字符串处理函数源码

2013-09-14 10:19 323 查看

1.拷贝字符串到目标字符串

char *strcpy(char *strDestination, const char *strSource);

复制源串strSource到目标串strDestination所指定的位置, 包含NULL结束符. 不能处理源串与目标串重叠的情况.

函数返回strDestination值.

char *strcpys(char *strDes, const char *strSrc)

{

assert((strDes != NULL) && (strSrc != NULL)); //assert用以检测是否为空,通过assert处理异常来返回NULL !!!!觉得这里好像这里有错,如果没有初始化呢、、??

char *address = strDes;

while ((*strDes ++ = *strSrc ++) != '\0')

NULL;

return address;

}



nt strcmp(const char *string1, const char *string2); 比较字符串string1和string2大小. 返回值< 0, 表示string1小于string2; 返回值为0, 表示string1等于string2; 返回值> 0, 表示string1大于string2.

int strcmp(const char *s, const char *t)

{ assert(s != NULL && t != NULL);

while (*s && *t && *s == *t)

{ ++ s; ++ t; }

return (*s - *t);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: