两个陈述互相贬值

时间:2016-07-03 03:16:46

标签: c printf character scanf

首先,我真的很抱歉这个怪异的标题,因为我不知道什么是最好的描述方式。我是C语言中的自学者,当我尝试打印角色时会出现问题。这是代码:

#include <stdio.h>

main()
{
int num;
float amt;
char ch;
long int pop_of_Indian;
printf("value of num: ");
scanf("%d", &num);
printf("value of amt: ");
scanf("%f", &amt);
printf("one character: ");
scanf("%c", &ch);
printf("Indian population: ");
scanf("%ld", &pop_of_Indian);

printf("NUM = %d\n AMT = %f\n Code = %c\n population of India is %ld\n", num, amt, ch, pop_of_Indian);
}

一切顺利运行,直到代码需要用户的角色: You can see the line requires character input from user is in the same line with Indian's population input requirement

但是,当我单独运行角色部分时,它会正常运行:

#include <stdio.h>
main()
{
char ch;
printf("one character: ");
scanf("%c", &ch);
printf("Code = %c \n", ch);
}

我在这里做错了什么?

0 个答案:

没有答案