注册 登录
编程论坛 C语言论坛

一个字符输出问题

蔚然与成风 发布于 2022-05-20 23:10, 1036 次点击
#include "stdio.h"

int main()
{
    char a;
    while(scanf("%c",&a) != EOF)
    {
        getchar(); // 如果我没写这个getchar(),输出的时候结果总是多个答案
    if(a == 'A' || a == 'a' || a == 'E' || a == 'e' || a == 'I'|| a == 'i' || a =='O'|| a == 'o'|| a == 'U' || a== 'u')
    {
        printf("Vowel\n");
    }
    else printf("Consonant\n");
    }
        return 0;
}
只有本站会员才能查看附件,请 登录

只有本站会员才能查看附件,请 登录
2 回复
#2
rjsp2022-05-21 01:47
回车不算字符吗?

程序代码:
#include <stdio.h>
#include <string.h>

int main( void )
{
    for( char ch; scanf(" %c",&ch)==1; ) // 注意 %c 前有一个空格
    {
        if( strchr("AEIOUaeiou",ch) )
            puts( "Vowel" );
        else
            puts( "Consonant" );
    }
}
#3
蔚然与成风2022-05-21 10:45
回复 2楼 rjsp
感谢感谢
1