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