Re: scanf() quesion?
- From: "zwgao83@xxxxxxxxx" <zwgao83@xxxxxxxxx>
- Date: 12 May 2007 04:52:50 -0700
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=
.
- Follow-Ups:
- Re: scanf() quesion?
- From: Bart van Ingen Schenau
- Re: scanf() quesion?
- From: Army1987
- Re: scanf() quesion?
- References:
- scanf() quesion?
- From: guoliang
- scanf() quesion?
- Prev by Date: UnUnderstandable typedef -- for me :-)
- Next by Date: Re: UnUnderstandable typedef -- for me :-)
- Previous by thread: Re: scanf() quesion?
- Next by thread: Re: scanf() quesion?
- Index(es):
Relevant Pages
|
|