【发布时间】:2015-05-30 00:35:00
【问题描述】:
请帮帮我。 我想知道为什么会这样。
此代码没有给出正确答案:
#include < stdio.h>
int main()
{
char c,ch;
int i;
printf("Welcome buddy!\n\nPlease input first character of your name: ");
scanf("%c",&c);
printf("\nPlease input first character of your lovers name: ");
scanf("%c",&ch);
printf("\nHow many children do you want? ");
scanf("%d",&i);
printf("\n\n%c loves %c and %c want %d children",c,ch,c,i);
return 0;
}
但是这段代码给出了正确的答案。
#include < stdio.h>
int main()
{
char c,ch;
int i;
printf("Welcome buddy!\n\nPlease input first character of your name: ");
scanf(" %c",&c);
printf("\nPlease input first character of your lovers name: ");
scanf(" %c",&ch);
printf("\nHow many children do you want? ");
scanf("%d",&i);
printf("\n\n%c loves %c and %c want %d children",c,ch,c,i);
return 0;
}
为什么? 以及如何?
请任何知道为什么会发生这种情况的人帮助我。
【问题讨论】:
-
我认为第二个答案to this question 可能会有所帮助。尤其是关于“跳过空格”的部分