【发布时间】:2014-12-13 17:57:41
【问题描述】:
我正在尝试找出字符串中元音的数量,但我不知道如何找到未初始化数组的长度。我将遍历所有数组元素并返回元音的数量。我浏览了论坛并读到有内置的 strlen 函数,但我想让我自己的函数理解工作不仅仅是完成我的工作。我已经使用 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.
}
}
【问题讨论】:
-
如果数组未初始化,则它没有长度。
-
您必须向 Number_of_vowels 添加一个长度参数。字符串的长度可以通过strlen(strin);获取到
标签: arrays string char string-length