www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

c++ - Another simple' printf ' problem

↑ ↓ ← "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
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
↑ ↓ → "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
→ "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