Re: scanf() quesion?



On May 11, 3:11 pm, "guoliang" <poster....@xxxxxxxxx> wrote:
help:

#include<stdio.h>

int main(void)
{
int a;
char b;

printf("int=");
scanf("%d",&a);
fflush(stdin);
printf("char=");
scanf("%c",&b);

printf("a=%d, str=%c\n",a,b);
return 0;}

input:1 and return;
output:char=a=1, b=

how can i assigment :a=1,b='x'?

it works fine for me .my environment is winxp+mingw gcc 3.4.2.
i find the fflush refrence from msdn:

The fflush function flushes a stream. If the file associated with
stream is open for output, fflush writes to that file the contents of
the buffer associated with the stream. If the stream is open for
input, fflush clears the contents of the buffer. fflush negates the
effect of any prior call to ungetc against stream. Also, fflush(NULL)
flushes all streams opened for output. The stream remains open after
the call. fflush has no effect on an unbuffered stream.

if you comment out fflush(stdin); ,the result is the same to yours:
char=a=1,b=

.



Relevant Pages

  • Re: Sending XML data via socket
    ... I looked int a link you have provided. ... // Get a stream object for reading and writing ... Resize the buffer, put in the byte we've just ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Trouble with custom InputStream being used by Readers
    ... wrong with my Stream. ... He'll fill his buffer. ... private final Object lock = new Object; ... public synchronized int read ...
    (comp.lang.java.programmer)
  • Re: I need help please!
    ... The fflush function flushes a stream. ... fflush clears the contents of the buffer. ... process input buffer: that data has "arrived" but if it hasn't reached ...
    (comp.lang.c)
  • Re: I need help please!
    ... function that will consume ALL the characters left in the standard input ... The fflush function flushes a stream. ... fflush clears the contents of the buffer. ...
    (comp.lang.c)
  • Re: how to check the scanf function if it will read more than one number
    ... It would do so as an extension. ... > The fflush function flushes a stream. ... > the buffer associated with the stream. ...
    (comp.lang.c)