古惑仔同门国语 优酷:C语言字符串处理函数
来源:百度文库 编辑:中科新闻网 时间:2024/05/21 22:17:17
C语言字符串处理函数的1。字符串连接函数2。字符串复制函数3。字符串比较函数4。测字符串长度函数,这些怎样不用程序库中专门的字符串处理函数表达,而用比较简单的原始的方法表达??
就是在编写中不能用到strcat,strcpy,strcmp,strlen这几个函数而达到这几个函数的效果,只需一个小例子给指导下。是C语言啊,不是C++啊
就是在编写中不能用到strcat,strcpy,strcmp,strlen这几个函数而达到这几个函数的效果,只需一个小例子给指导下。是C语言啊,不是C++啊
其实那些字符串函数并不复杂。任何一个的实现都不出五行代码:
char *strcpy( char *dst, const char *src ) {
char *destination = dst;
while( *dst++ = *src++ )
;
return destination;
}
char *strcat( char *dst, const char *src ) {
char *destination = dst;
while( *dst++ )
;
strcpy( --dst, src );
return destination;
}
int strcmp( const char *s1, const char *s2 ) {
for( ; *s1 == *s2; s1++, s2++ )
if( *s1 == '\0' ) return 0;
return *s1 - *s2;
}
unsigned strlen( const char *s ) {
const char *t = s;
while( *t++ )
;
return --t - s;
}
1,strcat(T*a,T*b);
2,strcpy(T*a,T*b);
3,strcmp(T*a,T*b);
4,strlen(T*A).
原始的方法,那就只好你自己写函数去实现了