带Eclipse CDT问题的Printf

带Eclipse CDT问题的Printf,c,printf,eclipse-cdt,C,Printf,Eclipse Cdt,长话短说,我正在运行EclipseCDT。下面是我的代码,一个简单的输入字符函数。但是,当我运行它(没有错误*)时,它要求我在显示printf语句之前为变量“c”输入一个字符。我尝试过使用puts语句以及制作两行printf,但都没有效果。请有人告诉我最佳解决方案,或者告诉我这是否更可能是eclipse cdt问题 #include <stdlib.h> #include <stdio.h> int main(void) { char c; printf

长话短说,我正在运行EclipseCDT。下面是我的代码,一个简单的输入字符函数。但是,当我运行它(没有错误*)时,它要求我在显示printf语句之前为变量“c”输入一个字符。我尝试过使用puts语句以及制作两行printf,但都没有效果。请有人告诉我最佳解决方案,或者告诉我这是否更可能是eclipse cdt问题

#include <stdlib.h>
#include <stdio.h>

int main(void)
{
    char c;
    printf("Please input a character: %c\n", c = getchar());
    if ((c >= 'a') && (c <= 'z'))
        printf("%c is a lower-case letter.", c);
    else if ((c >= 'A') && c<= 'Z')
        printf("%c is a capital letter.", c);
    else if ((c >= '0') && c <= '9')
        printf("%c is a digit!", c);
    return EXIT_SUCCESS;
}
#包括
#包括
内部主(空)
{
字符c;
printf(“请输入一个字符:%c\n”,c=getchar());

如果((c>='a')&&&(c='a')&&c='0')&&c在代码中,您将
c=getchar()
作为
printf
的参数。在调用
printf
之前,必须对该参数进行求值

您可能会更幸运地使用:

printf("Please input a character\n");
c = getchar();
虽然,当我阅读上面添加的注释时,听起来可能也存在缓冲问题,这将阻止写入输出。但请先尝试这一点。

这两行:

char c;
printf("Please input a character: %c\n", c = getchar());
不正确,这是您在打印前必须输入字符的原因

以下各项将正常工作:

int c;
printf("Please input a character: ");
fflush( stdout );
c = getchar();
您可能还想看看:

isupper()
islower()
isdigit()

我想这可能不是同一个问题…在下面添加了一个可能的答案。@jwismar:对,我没有领会。getchar()返回一个int,而不是char。你能解释一下这行具体做什么吗:根据“C编程语言”:fflush()的fflush(stdout)导致写入任何缓冲但未写入的数据;在输入流上,效果未定义。写入错误返回EOF,否则返回零。