去除字符串中重复出现的字符


/*****************************************************
copyright (C), 2016-2017, Lighting Studio. Co.,     Ltd. 
Author ChenYangYang   Date: 2016/12/19
Description:去除字符串中重复出现的字符
*****************************************************/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define MAX_SIZE 1024

void removestr(char *str,char *dest)
{
    int i;
    int j;
    int k = 0;
    int flag;
    int len;
    /*入口参数检查*/
    if(str == NULL || dest == NULL)
    {
        exit(0);
    }
    len = strlen(str);
    for(i = 0; i < len; i++)
    {
        flag = 1;
        for(j = 0; j < i; j++)
        {
            if(dest[j] == str[i])
                flag = 0;
        }
        if(flag)
            dest[k++] = str[i];
    }
    dest[k] = '\0';

}


int main()
{
    char str[MAX_SIZE];
    char dest[MAX_SIZE] = {"0"};
    printf("input str is:");
    scanf("%s",str);
    removestr(str,dest);
    printf("str = %s\n",str);
    printf("redest = %s\n",dest);
    return 0;
}





已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 终极编程指南 设计师:CSDN官方博客 返回首页