分类: C/C++
2009-09-28 15:34:53
|
fera2009-09-29 10:46:52
楼主你连抄都不会抄,原文里第二个比这个强多了,除了代码难看点。 // Solution 1. char * ReverseStringSlow(char * aStr) { int len = strlen(aStr); char * ptemp = (char*) malloc (len); for (int i = len - 1, j = 0; i >= 0; --i, ++j) { ptemp[j] = aStr[i]; } strncpy(aStr, ptemp, len); free(ptemp); return aStr; } // Solution 2: better one char * ReverseStringFast(char * aStr) { int len = strlen(aStr); char temp = '\0'; for(int i = 0; i < len / 2; ++i) {