*** 自写代码:删除字符串中所有指定的字符

#include <iostream>
#include <string.h>
using namespace std;
char * deleteChar (char * src, char c)
{
    if (src == NULL) return NULL;
    char * p = src;
    char * head = src;
    while (*p != '\0')
    {
        if (*p != c)
        {
            *head++ = *p;
        }
        p++;
    }
    *head = '\0';
    return src;
}
int main()
{
    char a[] = "132345336733333";
    cout << deleteChar(a, '3') << endl;
    return 0;
}

 

posted @ 2018-12-23 19:01  super行者  阅读(268)  评论(0编辑  收藏  举报