编辑代码

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

// 从字符串中移除重复的字符
void removeDuplicates(char *str) 
{
    // 如果字符串为空或长度小于等于1,则无需处理
    if (str == NULL) 
    {
        return;
    }
    int len = strlen(str);
    if (len <= 1)
    {
        return;
    }

    int tail = 1; // 新字符串的尾指针位置

    // 遍历整个字符串
    for (int i = 1; i < len; i++) 
    {
        int j;
        // 查找当前字符是否在新字符串中已经出现过
        for (j = 0; j < tail; j++) 
        {
            if (str[i] == str[j]) 
            {
                break;
            }
        }
        // 如果没有出现过,则添加到新字符串中
        if (j == tail) 
        {
            str[tail++] = str[i];
        }
    }

    str[tail] = '\0'; // 设置新字符串的终止符号
}

int main() 
{
    char str[101]; // 存储输入的字符串

    printf("请输入字符串:");
    fgets(str, sizeof(str), stdin); // 从标准输入读取字符串

    removeDuplicates(str); // 移除字符串中的重复字符

    printf("删除重复字符后的字符串为:%s\n", str); // 输出处理后的字符串

    return 0;
}