First, I'm really sorry for the weird title as I don't know what's the best way to describe. I'm a self-learner in C and there is a problem when I try to print the character. Here is the code:
#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);
}
Everything runs smoothly until the code required the character from user: You can see the line requires character input from user is in the same line with Indian's population input requirement
However, when I run the character part separately, it runs normally:
#include <stdio.h>
main()
{
char ch;
printf("one character: ");
scanf("%c", &ch);
printf("Code = %c \n", ch);
}
What am I doing wrong here?