- 1、本文档共9页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
C语言字符函串数实现源码汇总
C语言字符串函数实现源码汇总
2008年05月18日 星期日 16:54
1 /*2?? *?? linux/lib/string.c3?? *4?? *?? Copyright (C) 1991, 1992?? Linus Torvalds5?? */6 7 /*8?? * stupid library routines.. The optimized versions should generally be found9?? * as inline code in asm-xx/string.h10?? *11?? * These are buggy as well..12?? */13??14 #include linux/types.h15 16 char * ___strtok = NULL;17 18 char * strcpy(char * dest,const char *src)19 {20????????? char *tmp = dest;21 22????????? while ((*dest++ = *src++) != \0)23? ;24????????? return tmp;25 }26 27 char * strncpy(char * dest,const char *src,size_t count)28 {29????????? char *tmp = dest;30 31????????? while (count-- (*dest++ = *src++) != \0)32????????????????? /* nothing */;33 34????????? return tmp;35 }36 37 char * strcat(char * dest, const char * src)38 {39????????? char *tmp = dest;40 41????????? while (*dest)42????????????????? dest++;43????????? while ((*dest++ = *src++) != \0)44????????????????? ;45 46????????? return tmp;47 }48 49 char * strncat(char *dest, const char *src, size_t count)50 {51????????? char *tmp = dest;52 53????????? if (count) {54????????????????? while (*dest)55????????????????????????? dest++;56????????????????? while ((*dest++ = *src++)) {57????????????????????????? if (--count == 0)58????????????????????????????????? break;59????????????????? }60????????? }61 62????????? return tmp;63 }64 65 int strcmp(const char * cs,const char * ct)66 {67????????? register signed char __res;68 69????????? while (1) {70????????????????? if ((__res = *cs - *ct++) != 0 || !*cs++)71????????????????????????? break;72????????? }73 74????????? return __res;75 }76 77 int strncmp(const char * cs,const char * ct,size_t count)78 {79????????? register signed char __res = 0;80 81????????? while (count) {82????????????????? if ((__res = *cs - *ct++) != 0 || !*cs++)83????????????????????????? break;84????????????????? count--;85????????? }86 87????????? return __re
文档评论(0)