C語言中strcmp的實現原型
實現代碼:
int __cdecl 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 ; return( ret ); }
函數原型:int strcmp(const char *dest, const char *source) ;
返回值:返回整數值,如果dest > source,則返回值大于0,如果dest = source,則返回值等于0,如果dest < source ,則返回值小于0。字符大小是按照字符的字典序列進行排列的。
參數說明:都是以''/0''為結束符的字符串
實現;
int strcmp(const char *dest, const char *source) { assert((NULL != dest) && (NULL != source)); while (*dest && *source && (*dest == *source)) { dest ++; source ++; } return *dest - *source; /*如果dest > source,則返回值大于0,如果dest = source,則返回值等于0,如果dest < source ,則返回值小于0。*/ }
以上就是C語言中strcmp的實現原型的實例,如有疑問請留言或者到本站社區交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
新聞熱點
疑難解答
圖片精選