我試圖找出字符串中的元音數量,但我沒有找到未初始化數組長度的想法。我將遍歷所有的數組元素,並返回元音的否。我通過論壇並閱讀,有內置的strlen函數,但我想讓我自己的函數了解工作,不僅僅是我的工作done.i 「已經實現了這個使用for循環遍歷所有準備,但它是一個失敗..自定義函數來查找數組的長度?
char strin[];
printf("Check for the number of vowels in the string : \n");
scanf("%s" , &strin);
int Number_of_vowels(strin);
//a custom function to find the string length.
int string_len(char[] string)
{
//code to find the length
}
//a custom function to do the check.
int Number_of_vowels(char strin[])
{
for(i = 0 ; i < stringlength , i++)
{
//check if the input char is vowel.
}
}
如果數組未被初始化,那麼它沒有長度。 – csmckelvey 2014-12-13 17:59:14
您必須爲Number_of_vowels添加一個長度參數。一個字符串的長度可以通過strlen(strin)來檢索; – noxmetus 2014-12-13 18:03:02