Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Output/Input Problem

Reply
Thread Tools

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;

 
Reply With Quote
 
 
 
 
Martin Ambuhl
Guest
Posts: n/a
 
      10-11-2005
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.

 
Reply With Quote
 
 
 
 
Emmanuel Delahaye
Guest
Posts: n/a
 
      10-11-2005
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.
> You better try to read more info: try "man scanf".
>

Do it yourself...
 
Reply With Quote
 
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().
 
Reply With Quote
 
Emmanuel Delahaye
Guest
Posts: n/a
 
      10-11-2005
Aloo a écrit :
> Try using "fflush(stdin)"


Please stop saying insanities.
 
Reply With Quote
 
Emmanuel Delahaye
Guest
Posts: n/a
 
      10-11-2005
a écrit :
> just use fflush(stdin) to flush the input buffer so that it can show

Please stop saying insanities.
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem problem problem :( Need Help Mike ASP General 2 05-11-2004 08:36 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57