Velocity Reviews > Output/Input Problem

# Output/Input Problem

vivek.sriwastava@gmail.com
Guest
Posts: n/a

 10-11-2005
just use fflush(stdin) to flush the input buffer so that it can show
the prompt for the next character.
eg.
printf("Enter a ");
scanf("%c",&a);
fflush(stdin);
printf("Enter b ");
scanf("%c",&b);
fflush(stdin);
printf("b= %c\n",b);
return 0;

Martin Ambuhl
Guest
Posts: n/a

 10-11-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> just use fflush(stdin) to flush the input buffer so that it can show
> the prompt for the next character.

I can't believe we have had two suggestions in 24 hours that people use
undefined behavior. Please learn: "fflush() is not defined on input
streams."

We are told in the Lunyu (13.3) that Zilu put a silly claim to Kongzi.
Master Kong replied "How can you be so dense? Where an exemplary man is
ignorant, one should expect him to offer no opinion." This is a maxim
you should inscribe on your forehead. Or you could look up one of Dan
Pop's more colorful expressions of the same idea.

Emmanuel Delahaye
Guest
Posts: n/a

 10-11-2005
(E-Mail Removed) a écrit :
> scanf("%s", &a);
>
> %s - this switch allows you to read more characters from console if
> char a[..]; is declared like that or as a pointer.
>

Do it yourself...

Emmanuel Delahaye
Guest
Posts: n/a

 10-11-2005
Walter Roberson a écrit :
> scanf() with a %c format element reads *exactly* one character. You
> are entering two characters, the input you want and the newline to
> terminate the line. Thus after the first scanf(), you still have
> a character in the input buffer waiting to be read by the second
> scanf().

<all good things-for-level-4-gurus snipped>

Now you understand better why scanf() is for gurus only. Mean
programmers use fgets().

Emmanuel Delahaye
Guest
Posts: n/a

 10-11-2005
Aloo a écrit :
> Try using "fflush(stdin)"

Emmanuel Delahaye
Guest
Posts: n/a

 10-11-2005
(E-Mail Removed) a écrit :
> just use fflush(stdin) to flush the input buffer so that it can show

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules