나는 문장의 각 단어에서 모음 및 문자를 계산하는 방법을 알아 내려고 노력해 왔습니다. 예를문장의 각 단어에서 모음 및 문자 계산하기
를 들어 문장
hello : 5 characters, 2 vowels
there : 5 characters, 2 vowels
을 hello there
합니다. 나는 완전한 문장을 위해 같은 일을하는 코드를 보았다. 그러나 한 마디로 한마디도하지 말라. 다음은
lower case
될 것입니다 내가
int main() {
char str[512] = "hello there", word[256];
int i = 0, j = 0, v, h;
str[strlen(str)] = '\0';
/* checking whether the input string is NULL */
if (str[0] == '\0') {
printf("Input string is NULL\n");
return 0;
}
/* printing words in the given string */
while (str[i] != '\0') {
/* ' ' is the separator to split words */
if (str[i] == ' ')
{
for (h = 0; word[h] != '\0'; ++h)
{
if (word[h] == 'a' || word[h] == 'e' || word[h] == 'i' || word[h] == 'o' || word[h] == 'u')++v;
}
printf("\nVowels: %d", v);
word[j] = '\0';
printf("%s\n", word);
j = 0;
}
else
{
word[j++] = str[i];
}
i++;
}
word[j] = '\0';
/* printing last word in the input string */
printf("%s\n", word);
return 0;
}
작업했던 코드입니다. 나는 이것을 알아 내는데 어려움을 겪고있다.
코드를 실행하는 동안 모음 수가 많지 않습니다. 나는 그 문장을 나눌 수있다. 그러나 모음 카운팅은 일어나지 않습니다.
의 완벽한 ** 작동 * *. 단어의 문자를 세는 코드는 어디에 넣을 수 있습니까? 두 번째'사례'자체에서? –
@smashIT 해당 printf의 첫 번째 표현식은 단어 길이입니다. 사실, 그것을 단순화하기 위해 편집 할 것입니다. –
문자의 숫자를 인쇄 할 때, 마지막 단어에 대해 +1 숫자입니다. –