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


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

#include 
#include 
#include 

#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;
}





你可能感兴趣的:(算法)