问题描述
我用的getchar和的putChar到succeessfully打印我进入CHAR到屏幕前,但我已经改变了code稍微现在它打印我进入焦炭连续两次。 code:
I've used getchar and putchar to succeessfully print my entered char to the screen before, however I've changed the code slightly and now it prints my entered char twice in a row. Code:
#include <stdio.h>
int main()
{
int charInput;
printf("Enter a char >> ");
charInput = getchar();
printf("%c", putchar(charInput));
return 0;
}
我知道我可以只使用的putchar没有printf的,但我想与他们进行实验。我得到的输出是:
I know I could just use putchar without the printf but I wanted to experiment with them. The output I get is:
Enter a char >> a
aa
2字符都显示在屏幕上?
2 chars are printed to the screen?
推荐答案
的putchar(charInput)
将打印你的角色一次,然后将返回它的参数, charInput
。然后,这将被传递给的printf
,这再次打印相同的字符。
putchar(charInput)
will print your character once, and will then return its argument,charInput
. This then gets passed to printf
, which prints the same character again.
这篇关于在打印ANSI C一个char的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!