关于#c语言#的问题:”输入一个以回车结束的字符串(少于 80 个字符),输出其中所出现过的小写英文字母(重复出现的字母须忽略)

”输入一个以回车结束的字符串(少于 80 个字符),输出其中所出现过的小写英文字母(重复出现的字母须忽略);若无小写英文字母则输出“Not Found!”

以下代码由ChatGPT提供,仅供参考

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

#define MAX_LEN 80  // 字符串的最大长度

int main()
{
    char str[MAX_LEN];  // 存储输入的字符串
    int i, j, len;  // 循环变量和字符串长度
    int found = 0;  // 是否找到小写字母的标志
    
    // 输入字符串
    printf("Enter a string (less than %d characters):\n", MAX_LEN);
    fgets(str, MAX_LEN, stdin);

    // 计算字符串长度(不包括换行符)
    len = strlen(str);
    if (str[len - 1] == '\n')
    {
        len--;
    }

    // 遍历字符串,查找小写字母
    for (i = 0; i < len; i++)
    {
        // 忽略重复字母
        for (j = 0; j < i; j++)
        {
            if (str[i] == str[j])
            {
                break;
            }
        }

        // 如果字符是小写字母且未出现过,输出
        if (str[i] >= 'a' && str[i] <= 'z' && j == i)
        {
            printf("%c ", str[i]);
            found = 1;
        }
    }

    // 如果未找到小写字母,输出“Not Found!”
    if (!found)
    {
        printf("Not Found!");
    }

    return 0;
}