它應該是一個檢測它何時是元音的函式。但是,并沒有達到預期的效果
#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);
}
有什么辦法可以修復它以比較整個陣列?
uj5u.com熱心網友回復:
在檢查“A”后,無論它是否匹配,您都會回傳。您想檢查所有可能的元音,直到匹配或到達串列末尾。我也會使函式無效,因為您忽略了回傳碼。
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");
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/480905.html
