www.digitalmars.com         C & C++   DMDScript  

c++ - Another simple' printf ' problem

reply "john russell" <joru ukonline.co.uk> writes:
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.
Sep 08 2002
next sibling parent reply Larry Brasfield <larry_brasfield snotmail.com> writes:
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)
Sep 08 2002
parent "john russell" <joru ukonline.co.uk> writes:
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


 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


 printf command is not written to the screen. This only happens after a


 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)

Sep 10 2002
prev sibling parent "Walter" <walter digitalmars.com> writes:
"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

 printf command is not written to the screen. This only happens after a

 comand.

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