char sz[] = " 1 1 2";
char *space; //指向 空白字符
char *pstrc = sz;//sz 是 char sz[] = " 1 1 2";
while (*pstrc) {
if (' ' == *pstrc) { //如果发现空白
space = pstrc; //指向空白处
while (' ' == *++space); //找到非空白字符
if (0 == *space) break;
/* 交换空白处和非空白处 */
*space += *pstrc;
*pstrc = *space - *pstrc;
*space = *space - *pstrc;
}
pstrc++;
}
/* 最后一步!!!结束0 */
pstrc = sz;
while (' ' != *pstrc++);
*pstrc = 0;
相比上搞版本快了N倍了