C++ Code
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
char *strcpy1(char *strDest, const char *strSrc)
{ assert((strDest != NULL) && (strSrc != NULL)); char *address = strDest; while( (*strDest++ = * strSrc++) != ' ' ) ; return address ; } char *strcpy2(char *strDest, const char *strSrc) { assert(strSrc != NULL ); assert(strDest != NULL); int i; char *address = strDest; for(i = 0; strSrc[i] != ' '; i++) strDest[i] = strSrc[i]; strDest[i] = ' '; return address; } // chain operations int length = strlen( strcpy( strDest, "hello world") ); |