【发布时间】:2022-01-01 12:31:43
【问题描述】:
我需要帮助。 我正在编写一个程序来使用指针和函数计算和打印元音和辅音,我的代码编译成功但不显示结果。
它显示“您的文本计数:0 个元音和 0 个辅音”或“分段错误”
我无法找出问题所在。
#include <stdio.h>
#include <string.h>
#define SIZE 1000
void voyelle(char *word)
{
int i,n,cons=0,vowel=0;
n=strlen(word);
while(*word<n)
{
if((*word>='a'&& *word<='z')||(*word>='A'&& *word<='Z'))
{
if(*word=='a'|| *word=='A'|| *word=='e'||*word=='E'||*word=='i'||*word=='I'||*word=='o'||*word=='O'||*word=='u'||*word=='U')
{
vowel++;
}
else
cons ++;
}
word++;
}
printf(" Your text count:%d vowels and %d consonnants",vowel,cons);
}
int main(void)
{
char text[SIZE];
printf("Input your text: ");
fgets(text,SIZE,stdin);
voyelle(text);
return 0;
}
【问题讨论】:
标签: function if-statement pointers while-loop segmentation-fault