仅在与输入进行比较时检测数组的第一个元素。我已经尝试了很多事情,但都没有成功

Only detects the first element of the array when it's compared with the input. I've tried with a lot of things and it's doesn't work out

它应该是一个检测元音的函数。但是,结果并不如预期

#include <stdio.h>
#include <conio.h>

// It didn't work out. It failed

// It was supposed to be a function that detects when it's a vowel.
// But, it didn't work out as expected

int isVowel(char c) {
    char letters[] = {'A', 'I', 'U', 'E', 'O', 'a', 'i', 'u', 'e', 'o'};
    for (int i = 0; i <= 9; i++) /* It detects A, but nothing else*/ {
        if (letters[i] == c)
            return printf("A vowel\n");
        else 
            return printf("Not a vowel \n");
    }

}

int main() {
    char c;
    printf("Press a key: ");
    do {
        c = getch();
        char ans = isVowel(c);
    } while(c != 13);
}

有什么方法可以修复它以比较整个数组?

无论是否匹配,检查 'A' 后,您都在 returning。您想检查所有可能的元音,直到匹配或到达列表末尾。我也会使函数无效,因为您忽略了 return 代码。

void isVowel(char c) {
    char letters[] = {'A', 'I', 'U', 'E', 'O', 'a', 'i', 'u', 'e', 'o'};
    for (int i = 0; i <= 9; i++) /* It detects A, but nothing else*/ {
        if (letters[i] == c)
            printf("A vowel\n");
            return;
    }

    printf("Not a vowel \n");
 }

}