删除 C 风格字符串中间的 '*'(不用库函数)

char* removeMiddleStar(char *str)
{
        if (!str)
                return str;
        char *p = str;
        for(; *p == '*'; ++p);
        char *q = p;
        while(*++q != '\0');
        while(*--q == '*');
        for (char *k = p; *k != '\0'; ++k)
                if ((k < q && *k != '*') || k >= q)
                        *p++ = *k;
        *p = '\0';
        return str;
}

 

posted @ 2016-03-03 17:51  wu_overflow  阅读(427)  评论(0编辑  收藏  举报