// 不用库函数实现strcmp #include <stdio.h> #include <assert.h> int my_strcmp( char const *p,char const *q ) { assert( ( *p != NULL ) && ( *q != NULL ) ); while( *p == *q ) { if( *p == '\0') { return 0; } p++; q++; } if( *p > *q ) { return 1; } else { return -1; } } int main() { char *p = "aebh"; char *q = "addfg"; printf("%d\n",my_strcmp( p,q )); return 0; }
<img src="http://img.blog.csdn.net/20150330230907026?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemhhb3lhcWlhbjU1Mg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
时间: 2024-10-04 18:26:32