home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / programm / 3091 < prev    next >
Encoding:
Text File  |  1992-11-09  |  1.9 KB  |  46 lines

  1. Newsgroups: comp.programming
  2. Path: sparky!uunet!utcsri!torn!nott!bnrgate!bcrka451!bcrki65!sjm
  3. From: sjm@bcrki65.bnr.ca (Stuart MacMartin)
  4. Subject: Re: HELP with scanf/getchar!
  5. Message-ID: <1992Nov9.205548.5984@bcrka451.bnr.ca>
  6. Sender: 5E00 Corkstown News Server
  7. Organization: Bell-Northern Research Ltd., Ottawa, Canada
  8. References: <1992Nov9.162547.11163@seas.smu.edu>
  9. Date: Mon, 9 Nov 1992 20:55:48 GMT
  10. Lines: 34
  11.  
  12. In article <1992Nov9.162547.11163@seas.smu.edu> pedersen@seas.smu.edu (Ted Pedersen) writes:
  13. >
  14. >The following is an annoying little problem that I just can't figure
  15. >out. I'm trying to get the program to prompt me for how many
  16. >characters I want to enter and then once I have said how many
  17. >characters I want I want the program to ask me to input those
  18. >characters.
  19. >
  20. >What really happens is that it asks me how many characters I want. I
  21. >input that and then my program sits. When I input the appropriate
  22. >number of characters the program goes ahead and prints out the message
  23. >asking for characters and then runs the program ok. 
  24. >
  25. >It seems like this is running out of order. Anyone have any idea as to
  26. >what might be going on?
  27. >
  28. >Thanks,
  29. >Ted Pedersen
  30. >--------------------------------------------------------------------
  31. You need to flush your buffers.  This is normally done with a '\n', but
  32. if you don't have that, you need to explicitly call fflush:
  33.  
  34. >    printf ("Enter number of characters you want : ");
  35.      fflush(stdout);   /* <=== THIS LINE WAS MISSING */
  36. >    scanf ("%d\n", &count);
  37. >    printf ("Enter your characters :");
  38.      fflush(stdout);   /* <=== THIS LINE WAS MISSING */
  39. >    for (loop = 0; loop < count; loop++) {
  40.  
  41. Stuart
  42. --
  43. : Stuart MacMartin                                    email: sjm@bnr.ca      :
  44. : Bell-Northern Research                              phone: (613) 763-5625  :
  45. : PO Box 3511, Stn C, Ottawa, K1Y-4H7, CANADA    Standard disclaimers apply. :
  46.