Hi everyone
I wrote three simple functions to ask user enter something.
They are in the same format like following
int askN(void)
{
int n = 0;
printf("enter n-> ");
scanf("%d", &n);
return n;
Quote:
}
int askR(void)
{
int r = 0;
printf("enter r-> ");
scanf("%d", &r);
return r;
Quote:
}
the third one is
char doMore(void)
{
char ans;
printf("enter (Y/N)-> ");
scanf("%c",&ans);
return ans;
Quote:
}
Now my question is when I called this three funcitons in main(),
the order really matterd. Why??
int main(void)
{
int n, r;
char answer;
n = askN();
printf("you entered %d\n", n);
r = askR();
printf("you entered %d\n", r);
answer = doMore();
printf("you entered %c\n", answer);
return 0;
Quote:
}
the order above caused problem. It won't let the user enter anything and
it just printed the following message.
But if I call the doMore() before the other two functions, it works fine.
It seems something is inside my standard input buffer. so my scanf() just
grabed that and printed next message.
I can not figure out why it behaves in this way.
thanks a lot, guys.