c语言中, 字符型变量的输入中,getchar怎么用?最好举个例子,谢谢!

如题所述

getchar()就是输入一个字符的意思,相当于scanf("%c",&d),变量d已经定义为字符型

举个简单的例子

#include <stdio.h>
void main()
{
char d;
d=getchar();
printf("%c\n",d);

}

输入一个d,将输出d

追问

我的美好未来就需要您这样的及时雨!!求qq

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-10-05
c = getchar();
is an expression and has a value, which is the value of the left hand side after the assignment.
This means that a assignment can appear as part of a larger expression. If the assignment of a
character to c is put inside the test part of a while loop, the copy program can be written this
way:
#include <stdio.h>
/* copy input to output */
main()
{
int c;
while((c = getchar()) != EOF)
putchar(c);
}追问

仰慕……您q多少?

本回答被网友采纳
第2个回答  2013-10-05

这个问题比较抽象,遇到这种问题,自己写一个程序试试,比如:

#include <stdio.h>
#include <iostream>
int main()
{
    char a;
    a=getchar();
    printf("%c\n",a);
    system ("pause");
    return 0;
}

输入 abc
输入 a

追问

仰望中……能加您q吗?

相似回答