我的代码一直在不断扫描文本,我不知道发生了什么问题

问题描述 投票:0回答:1

我要做的就是计算一个短语中有多少个字母(单词之间没有空格),计算出多少个元音和多少个辅音。如果字母的数量是偶数,辅音的数量可以被元音的数量整除,那么我将打印“是”。否则,我将打印“否”

int main(int argc, char const *argv[]){
    int texts;

    scanf("%d", &texts);

    int vowel, consonant, letter, count, k;
    char text[1000];

    for(k = 0; k < texts; k++){

        scanf("%s", text);

        letter = 0;
        count = 0;
        while(text[count] != '\0'){
            count++;
            letter++;
        }

        count = 0;
        vowel = 0;
        consonant = 0;

        while(text[count] != '\0'){
            if(text[count] == 'a' || text[count] == 'e' || text[count] == 'i' || text[count] == 'o' || text[count] == 'u'){
                vowel++;
            }else if(text[count] != 'a' || text[count] != 'e' || text[count] != 'i' || text[count] != 'o' || text[count] != 'u'){
                consonant++;
            }
        }
        if((consonant % vowel == 0) && (letter % 2 == 0)){
            printf("yes");
        }else{
            printf("no");
        }
    }
    return 0;
}

但是它一直持续扫描,我不存在问题所在。感谢任何帮助,谢谢。

c loops infinite
1个回答
0
投票

问题出在这里

        while(text[count] != '\0'){
        count++;
        letter++;
        }

它永远不会退出此循环,您应该搜索''

        while(text[count] != ' '){
        count++;
        letter++;
        }

为将来对dubug程序提供参考,请在代码的不同部分中添加带数字的printfs,以便您知道程序在做什么:)

© www.soinside.com 2019 - 2024. All rights reserved.