home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / os / os2 / programm / 4334 < prev    next >
Encoding:
Text File  |  1992-08-19  |  2.0 KB  |  66 lines

  1. Newsgroups: comp.os.os2.programmer
  2. Path: sparky!uunet!mdisea!lmorris
  3. From: lmorris@mdd.comm.mot.com (Larry Morris)
  4. Subject: Re: Question and problem with GCC/2
  5. Message-ID: <1992Aug20.010531.28610@mdd.comm.mot.com>
  6. Sender: news@mdd.comm.mot.com
  7. Organization: Motorola, Mobile Data Division - Seattle, WA
  8. References: <1992Aug19.212328.15304@talon.ucs.orst.edu>
  9. Distribution: na
  10. Date: Thu, 20 Aug 1992 01:05:31 GMT
  11. Lines: 53
  12.  
  13. In <1992Aug19.212328.15304@talon.ucs.orst.edu> hilmera@ucs.orst.edu (Andrew Hilmer) writes:
  14.  
  15. >Compiler: gcc/2 2.1
  16. >Problem: problem and question about gcc/2
  17.  
  18. ...
  19.  
  20. >/*
  21. >  This program takes the input of two numbers, one
  22. >  integer, one floating point, and prints them back out.
  23. >*/
  24.  
  25. >#include <stdio.h>
  26.  
  27. >main()
  28. >{
  29. >  int x;
  30. >  float y;
  31.  
  32. >/*  fflush(stdin); */
  33. >  printf("This is my first C program.\n");
  34. >  printf("Enter an integer: ");
  35. >  scanf("%d", &x);
  36. >  printf("Enter a floating point number: ");
  37. >  scanf("%f", &y);
  38. >  printf("The value stored in x is %d\n", x);
  39. >  printf("The value stored in y is %f\n", y);
  40. >}
  41.  
  42. ...
  43.  
  44. >When run, it prints nothing but a line or two and a blinking cursor.
  45. >As a shot in the dark, I entered 3, hit enter (got another big
  46. >nothing), then entered 93.9 and hit enter.
  47.  
  48. Read  the FAQ.  Nothing says when stdout will flush unless you specify it.
  49. The program did exactly as requested. 
  50.     printf() some stuff   --  it gets buffered to stdout
  51.     scanf() some stuff    --  you typed 3
  52.     printf() some more    --  stdout buffers some more
  53.     scanf() some more     --  you typed 93.9
  54.     exit()        -- stdout gets flushed at exit and you see the printfs()
  55.  
  56. If you want to handle the flushes yourself, just fflush(stdout)  before each
  57. of the scanfs().  Takes full advantage of any buffering and gets you exactly
  58. what you want.
  59.  
  60.  
  61. -- 
  62. Internet:    <lmorris@mdd.comm.mot.COM>   |  Larry Morris
  63.  ...uw-beaver!sunup-----\                 |  Motorola/Mobile Data Division
  64.  ...uunet-----------------!mdisea!lmorris |  19807 North Creek Parkway
  65.  ...van-bc!mdivax1------/                 |  Bothell, WA  (206) 487-5810
  66.