欢迎来到天天文库
浏览记录
ID:13216902
大小:23.84 KB
页数:31页
时间:2018-07-21
《c语言标准库源码(string 部分)(c language standard library source code (string part))》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、c语言标准库源码(string部分)(Clanguagestandardlibrarysourcecode(stringpart))Clanguagestringprocessingstandardlibraryfunctionsource(turn)#ifndef__HAVE_ARCH_STRNICMP/***strnicmp-Caseinsensitive,length-limitedstringcomparison*@s1:Onestring*@s2:Theotherstring*@len:themaximumnumberofcharacterstocompar
2、e*/Intstrnicmp(constchar*s1,constchar*s2,size_tlen){YesVirginia,ithad*,better*beunsignedUnsignedcharC1,c2;C1=0;C2=0;If(len){{doC1=*s1;C2=*s2;S1++;s2++;If(...C1)Break;If(...C2)Break;If(C1=C2)Continue;C1=tolower(C1);C2=tolower(C2);If(C1==C2)Break;}while(--len);}Return(int)C1-(int)c2;}#end
3、ifChar*___strtok;#ifndef__HAVE_ARCH_STRCPY/***strcpy-Copya%NULterminatedstring*@dest:Wheretocopythestringto*@src:Wheretocopythestringfrom*/Char*strcpy(char*DeST,constchar*src){Char*tmp=dest;While((*dest++=*src++)=' ')Nothing/**/;Returntmp;}#endif#ifndef__HAVE_ARCH_STRNCPY/***strncpy-Co
4、pyalength-limited,%NUL-terminatedstring*@dest:Wheretocopythestringto*@src:Wheretocopythestringfrom*@count:Themaximumnumberofbytestocopy**Notethatunlikeuserspacestrncpy,thisdoesnot%NUL-padthebuffer.*However,theresultisnot%NUL-terminatedifthesourceexceeds*@countbytes.*/Char*strncpy(char*D
5、eST,constchar*src,size_tcount){Char*tmp=dest;While(count--(*dest++=*src++)!=' ')Nothing/**/;Returntmp;}#endif#ifndef__HAVE_ARCH_STRCAT/***strcat-Appendone%NUL-terminatedstringtoanother*@dest:Thestringtobeappendedto*@src:Thestringtoappendtoit*/Char*strcat(char*DeST,constchar*SRC){Char*t
6、mp=dest;While(*dest)Dest++;While((*dest++=*src++)=' ');Returntmp;}#endif#ifndef__HAVE_ARCH_STRNCAT/***strncat-Appendalength-limited,%NUL-terminatedstringtoanother*@dest:Thestringtobeappendedto*@src:Thestringtoappendtoit*@count:Themaximumnumbersofbytestocopy**Notethatincontrasttostrncpy
7、,strncatensurestheresultis*terminated.*/Char*strncat(char*dest,constchar*src,size_tcount){Char*tmp=dest;If(count){While(*dest)Dest++;While((*dest++=*src++)){If(--count==0){*dest=' ';Break;}}}Returntmp;}#endif#ifndef__have_Arch_strcmp/***strcmp-comparetwostrings*@CS:OneString*@
此文档下载收益归作者所有