All of lore.kernel.org
 help / color / mirror / Atom feed
* buggy_double_use_of _scanf
@ 2004-10-26 12:42 simon
  2004-10-26 20:59 ` Glynn Clements
  0 siblings, 1 reply; 5+ messages in thread
From: simon @ 2004-10-26 12:42 UTC (permalink / raw)
  To: linux-C-programming

hello,

I have observe a strange scanf behaviour...
when using two successive scanf... the second receive a return character

for example :

int a;
char b;

scanf ("%d", &a);
fflush (stdin);
scanf ("%c", &b);
fprintf (stdout, "a : %d\nb : %c\n", a, b);

what's the problem ?
is scanf using a buggy internal buffer ?

simon

^ permalink raw reply	[flat|nested] 5+ messages in thread
* RE: buggy_double_use_of _scanf
@ 2004-11-01 22:25 Huber, George K RDECOM CERDEC STCD SRI
  0 siblings, 0 replies; 5+ messages in thread
From: Huber, George K RDECOM CERDEC STCD SRI @ 2004-11-01 22:25 UTC (permalink / raw)
  To: 'Fábio Russo', Glynn Clements, simon; +Cc: linux-C-programming

Hi,

Russo wrote:

[... snip ...]

>The problem, I beleve is in the fflush function. I Have the same behaviour
>with this source code, but when I put a additional scanf in the line, all 
>works fine -;)

>Now I ask:
>Why the fflush function did not remove the new line caracter when it
should?

quoteth the man page:

'The function fflush forces a write of all user-space buffered data for
 the given output or update stream via the stream's underlying write 
 function.'

Thus fflush only causes user-space buffered data to write their contents to 
the kernel-space buffers (which can be forced to update to the storage
medium
via a call to sync or fsync).  fflush has no effect when called on stdin - 
you are reading data not writing it.

George

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-11-02  3:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-10-26 12:42 buggy_double_use_of _scanf simon
2004-10-26 20:59 ` Glynn Clements
2004-11-01 19:03   ` Fábio Russo
2004-11-02  3:44     ` Glynn Clements
  -- strict thread matches above, loose matches on Subject: below --
2004-11-01 22:25 Huber, George K RDECOM CERDEC STCD SRI

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.