Online Compiler C

#include <stdio.h> #include <string.h> int isVowel(char s) { char* vowels = "aeoiuyAEOIUY"; if (strchr(vowels, s) != NULL) { return 1; } return 0; } int main(void) { char s[1005] = {0}; scanf("%[^\n]", s); for (int i = 0; s[i] != '\0'; i++) { if (!isVowel(s[i])) { putchar(s[i]); } } printf("\n"); return 0; }
这段代码的功能是:读取一行字符串,然后输出其中所有非元音字母(辅音字母)的字符。它定义了一个 `isVowel` 函数来判断字符是否为元音(包括大小写),主函数中遍历字符串并跳过元音,只打印其他字符。

- 你的 `isVowel` 函数中,元音字母列表 `"aeoiuyAEOIUY"` 包含了字母 `y` 和 `Y`。请确认这是否符合题目要求,通常元音只包括 a、e、i、o、u,不包括 y。
- 注意 `scanf("%[^\n]", s)` 的用法:它读取直到换行符为止,但不会消耗换行符。如果后续有输入操作可能会受影响,不过当前代码中只有一次输入,所以问题不大。