基于C语言的strcmp,strcpy,strcat函数的实现。C语言是一个程序员的基础,一定要重视。
char* strcat ( char * dst , const char * src ) { char * cp = dst; while( *cp ) cp++; /* find end of dst */ while( *cp++ = *src++ ) ; /* Copy src to end of dst *///一直到赋完'\0' return( dst ); /* return dst */ } char* strcpy(char * dst, const char * src) { char * cp = dst; while( *cp++ = *src++ ) ; /* Copy src over dst */ return( dst ); } int 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 ); }
时间: 2024-10-19 08:15:01