1. ibc(Linux下的ANSI C的函数库)
- char * strcat(char * dest, const char * src)
- {
- char *tmp = dest;
-
- while (*dest)
- dest++;
- while ((*dest++ = *src++) != '\0')
- ;
-
- return tmp;
- }
2. 微软
- char* strcat ( char * dst , const char * src )
- {
-
- char * cp = dst;
-
- while( *cp )
-
- cp++;
-
- while( *cp++ = *src++ ) ;
-
- return( dst );
-
- }
3. GNU C Library对这个函数的实现如下:
- char * strcat (char *dest, const char *src)
- {
-
- strcpy (dest + strlen (dest), src);
- return dest;
- }
4,OpenBSD对这个函数的实现如下:
- char * strcat(char *s, const char *append)
- {
-
- char *save = s;
-
-
- for (; *s; ++s);
-
-
- while ((*s++ = *append++) != '\0');
-
-
- return(save);
- }
5. 网上实现:
- #include <assert.h>
- char *strcat (char * dst, const char * src)
- {
- assert(NULL != dst && NULL != src);
- char * cp = dst;
- while( *cp )
- cp++;
- while( *cp++ = *src++ ) ;
- return( dst );
- }
写成下面这样或许好理解一点。
- char *strcat (char * dst, const char * src)
- {
- assert(NULL != dst && NULL != src);
- char * cp = dst;
- while( '\0' != *cp )
- cp++;
- while( '\0' != (*cp++ = *src++) ) ;
- return( dst );
- }