Article View: comp.os.os2.programmer
Article #1143Re: Question and problem with GCC/2
From: Larry Morris
Date: Thu, 20 Aug 1992 01:05
Date: Thu, 20 Aug 1992 01:05
53 lines
2128 bytes
2128 bytes
In <1992Aug19.212328.15304@talon.ucs.orst.edu> hilmera@ucs.orst.edu (Andrew Hilmer) writes:
>Compiler: gcc/2 2.1
>Problem: problem and question about gcc/2
...
>/*
> This program takes the input of two numbers, one
> integer, one floating point, and prints them back out.
>*/
>#include <stdio.h>
>main()
>{
> int x;
> float y;
>/* fflush(stdin); */
> printf("This is my first C program.\n");
> printf("Enter an integer: ");
> scanf("%d", &x);
> printf("Enter a floating point number: ");
> scanf("%f", &y);
> printf("The value stored in x is %d\n", x);
> printf("The value stored in y is %f\n", y);
>}
...
>When run, it prints nothing but a line or two and a blinking cursor.
>As a shot in the dark, I entered 3, hit enter (got another big
>nothing), then entered 93.9 and hit enter.
Read the FAQ. Nothing says when stdout will flush unless you specify it.
The program did exactly as requested.
printf() some stuff -- it gets buffered to stdout
scanf() some stuff -- you typed 3
printf() some more -- stdout buffers some more
scanf() some more -- you typed 93.9
exit() -- stdout gets flushed at exit and you see the printfs()
If you want to handle the flushes yourself, just fflush(stdout) before each
of the scanfs(). Takes full advantage of any buffering and gets you exactly
what you want.
--
Internet: <lmorris@mdd.comm.mot.COM> | Larry Morris
...uw-beaver!sunup-----\ | Motorola/Mobile Data Division
...uunet-----------------!mdisea!lmorris | 19807 North Creek Parkway
...van-bc!mdivax1------/ | Bothell, WA (206) 487-5810
Technical Details
Message-ID:
<1992Aug20.010531.28610@mdd.comm.mot.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!mdisea!lmorrisReferences:
<1992Aug19.212328.15304@talon.ucs.orst.edu>Show Full Headers
Complete Article Headers
Newsgroups: comp.os.os2.programmer Path: arc1-ca.pugleaf.net!sparky!uunet!mdisea!lmorris From: lmorris@mdd.comm.mot.com (Larry Morris) Subject: Re: Question and problem with GCC/2 Message-ID: <1992Aug20.010531.28610@mdd.comm.mot.com> Sender: news@mdd.comm.mot.com Organization: Motorola, Mobile Data Division - Seattle, WA References: <1992Aug19.212328.15304@talon.ucs.orst.edu> Distribution: na Date: Thu, 20 Aug 1992 01:05:31 GMT Lines: 53