Thread overview
Another simple' printf ' problem
Sep 08, 2002
john russell
Sep 08, 2002
Larry Brasfield
Sep 10, 2002
john russell
Sep 09, 2002
Walter
September 08, 2002
I'm slowly getting into C using DM IDDE, but I'm having a problem with the following program. I'm using the IDDE on a XP machine.

#include <stdio.h>

int main(void)
{
   int x;
   printf("Input value is: ");
   scanf("%d",&x);
   printf("\nvalue is %d ",x);

   getchar();
   return 0;


}

Why does the output window disappear after I input the number 'x'. The last printf command is not written to the screen. This only happens after a scanf comand.


September 08, 2002
In article <algifn$31bk$1@digitaldaemon.com>, john russell (joru@ukonline.co.uk) says...
> I'm slowly getting into C using DM IDDE, but I'm having a problem with the following program. I'm using the IDDE on a XP machine.
> 
> #include <stdio.h>
> 
> int main(void)
> {
>    int x;
>    printf("Input value is: ");
>    scanf("%d",&x);
>    printf("\nvalue is %d ",x);
> 
>    getchar();
>    return 0;
> 
> 
> }
> 
> Why does the output window disappear after I input the number 'x'. The last printf command is not written to the screen. This only happens after a scanf comand.

Look up the flush() or fflush() library calls.
Also, since scanf leaves the non-number input
on the stream, your getchar() call may not do
what you expect with respect to waiting.

--Larry Brasfield
(address munged, s/sn/h/ to reply)
September 09, 2002
"john russell" <joru@ukonline.co.uk> wrote in message news:algifn$31bk$1@digitaldaemon.com...
> I'm slowly getting into C using DM IDDE, but I'm having a problem with the following program. I'm using the IDDE on a XP machine.
>
> #include <stdio.h>
>
> int main(void)
> {
>    int x;
>    printf("Input value is: ");
>    scanf("%d",&x);
>    printf("\nvalue is %d ",x);
>
>    getchar();
>    return 0;
>
>
> }
>
> Why does the output window disappear after I input the number 'x'. The
last
> printf command is not written to the screen. This only happens after a
scanf
> comand.

You need to open a console window (also called a command prompt), and run the program from within that.


September 10, 2002
Thanks. Have solved problem using _flushall as shown below #include <stdio.h>

int main(void)
{
   int x,empty;
   x=100;
   printf("Input value is: ");
   scanf("%d",&x);
   printf("\nvalue is %d ",x);

   empty=_flushall();

   getchar();
   return 0;


}

Thanks again for your help.

"Larry Brasfield" <larry_brasfield@snotmail.com> wrote in message news:MPG.17e583936b6b94ba989692@news.digitalmars.com...
> In article <algifn$31bk$1@digitaldaemon.com>,
> john russell (joru@ukonline.co.uk) says...
> > I'm slowly getting into C using DM IDDE, but I'm having a problem with
the
> > following program. I'm using the IDDE on a XP machine.
> >
> > #include <stdio.h>
> >
> > int main(void)
> > {
> >    int x;
> >    printf("Input value is: ");
> >    scanf("%d",&x);
> >    printf("\nvalue is %d ",x);
> >
> >    getchar();
> >    return 0;
> >
> >
> > }
> >
> > Why does the output window disappear after I input the number 'x'. The
last
> > printf command is not written to the screen. This only happens after a
scanf
> > comand.
>
> Look up the flush() or fflush() library calls.
> Also, since scanf leaves the non-number input
> on the stream, your getchar() call may not do
> what you expect with respect to waiting.
>
> --Larry Brasfield
> (address munged, s/sn/h/ to reply)