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

来源:互联网 发布:json接口api 编辑:程序博客网 时间:2024/05/16 01:40


/*****************************************************copyright (C), 2016-2017, Lighting Studio. Co.,     Ltd. Author ChenYangYang   Date: 2016/12/19Description:去除字符串中重复出现的字符*****************************************************/#include <stdio.h>#include <string.h>#include <stdlib.h>#define MAX_SIZE 1024void 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;}


0 0
原创粉丝点击