9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] APE question
@ 2001-10-12 14:21 pac
  0 siblings, 0 replies; 10+ messages in thread
From: pac @ 2001-10-12 14:21 UTC (permalink / raw)
  To: 9fans

Friends,

under APE, the following part of code:

                printf("\nQuit [q], confirm [y], or change [menu] settings: ");               
                /* read one char */
                ch = getchar();
 
does not print out the message before waiting for a character input, unless it is flushed
e.g. by adding 
	printf("\n");
before line 3. Is this an intention? If so, could you tell me a better workaround than this with blank printf()?

Sorry fot ignorance,
--peter.

--
Peter A Cejchan
biologist
Acad. Sci., Prague, CZ
<cej at cejchan dot gli dot cas dot cz>



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [9fans] APE question
  2001-10-12 14:33 pac
                   ` (2 preceding siblings ...)
  2001-10-12 14:45 ` Howard Trickey
@ 2001-10-15  9:11 ` Douglas A. Gwyn
  3 siblings, 0 replies; 10+ messages in thread
From: Douglas A. Gwyn @ 2001-10-15  9:11 UTC (permalink / raw)
  To: 9fans

pac wrote:
> If only I were a bit better programmer to figure out that fflush()
> works with stdout, too (sigh, sigh)...

Actually, fflush() is not required to "flush" type-ahead input
on stdin; it has undefioned behavior on input streams.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [9fans] APE question
  2001-10-12 14:58   ` Howard Trickey
@ 2001-10-15  4:20     ` pac
  0 siblings, 0 replies; 10+ messages in thread
From: pac @ 2001-10-15  4:20 UTC (permalink / raw)
  To: 9fans

Hi,

thanks to all who answered! I have still much, much to learn!

--peter


--
Peter A Cejchan
biologist
Acad. Sci., Prague, CZ
<cej at cejchan dot gli dot cas dot cz>



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [9fans] APE question
  2001-10-12 14:45 ` Howard Trickey
@ 2001-10-12 14:58   ` Howard Trickey
  2001-10-15  4:20     ` pac
  0 siblings, 1 reply; 10+ messages in thread
From: Howard Trickey @ 2001-10-12 14:58 UTC (permalink / raw)
  To: Howard Trickey, 9fans

Whoops,
	setvbuf(stdout, _IONBF, BUFSIZ);
should have been
	setvbuf(stdout, 0, _IONBF, BUFSIZ);



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [9fans] APE question
  2001-10-12 14:33 pac
  2001-10-12 14:34 ` Boyd Roberts
  2001-10-12 14:40 ` Laura Creighton
@ 2001-10-12 14:45 ` Howard Trickey
  2001-10-12 14:58   ` Howard Trickey
  2001-10-15  9:11 ` Douglas A. Gwyn
  3 siblings, 1 reply; 10+ messages in thread
From: Howard Trickey @ 2001-10-12 14:45 UTC (permalink / raw)
  To: 9fans

> under APE, the following part of code:

>       printf("\nQuit [q], confirm [y], or change [menu] settings: ");
>        /* read one char */
>        ch = getchar();

According to the C standard, "The standard input and output streams are
fully buffered if and only if the stream can be determined not to refer to
an interactive device."  It doesn't say whether to use line buffering or no
buffering in the interactive case.  I chose line buffering.  So the above
might have worked if you'd put a '\n' at the end of the printf string.  (But
only "might": the code to test whether a file is "interactive" ---
isatty --- is hacky in the extreme, and only works sometimes; with Plan 9's
namespace stuff, it is hard to get right.)

As well as the fflush solution given earlier, you could also put a call like

	setvbuf(stdout, _IONBF, BUFSIZ);

near the beginning of your program.  But the fflush solution is probably
better.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [9fans] APE question
  2001-10-12 14:33 pac
  2001-10-12 14:34 ` Boyd Roberts
@ 2001-10-12 14:40 ` Laura Creighton
  2001-10-12 14:45 ` Howard Trickey
  2001-10-15  9:11 ` Douglas A. Gwyn
  3 siblings, 0 replies; 10+ messages in thread
From: Laura Creighton @ 2001-10-12 14:40 UTC (permalink / raw)
  To: 9fans

Heh.  What you need is a month or so watching us try to do 
computational biology.  You would be most amused.

Laura Creighton


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [9fans] APE question
  2001-10-12 14:33 pac
@ 2001-10-12 14:34 ` Boyd Roberts
  2001-10-12 14:40 ` Laura Creighton
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 10+ messages in thread
From: Boyd Roberts @ 2001-10-12 14:34 UTC (permalink / raw)
  To: 9fans

pac wrote:
> I'll give it a try. If only I were a bit better programmer to
> figure out that fflush() works with stdout, too (sigh, sigh)...

Oh, stdio buffering has never been straightforward or obvious.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [9fans] APE question
@ 2001-10-12 14:33 pac
  2001-10-12 14:34 ` Boyd Roberts
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: pac @ 2001-10-12 14:33 UTC (permalink / raw)
  To: 9fans


>> 
>> Put an fflush(stdout) twixt the printf and getchar?
I'll give it a try. If only I were a bit better programmer to figure out that fflush() works with stdout, too (sigh, sigh)...

--cheers, peter



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [9fans] APE question
@ 2001-10-12 14:32 rog
  0 siblings, 0 replies; 10+ messages in thread
From: rog @ 2001-10-12 14:32 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 356 bytes --]

i think on some platforms reading from stdin does an automatic flush on
stdout.  this might even be the standard.

anyway, it's probably safer to do

                printf("\nQuit [q], confirm [y], or change [menu] settings: ");   
                fflush(stdout);            
                /* read one char */
                ch = getchar();


[-- Attachment #2: Type: message/rfc822, Size: 1951 bytes --]

To: 9fans@cse.psu.edu
Subject: [9fans] APE question
Date: Fri, 12 Oct 2001 16:21:26 +0200
Message-ID: <cej-1011012162124.A01246@cejchan.gli.cas.cz>

Friends,

under APE, the following part of code:

                printf("\nQuit [q], confirm [y], or change [menu] settings: ");               
                /* read one char */
                ch = getchar();
 
does not print out the message before waiting for a character input, unless it is flushed
e.g. by adding 
	printf("\n");
before line 3. Is this an intention? If so, could you tell me a better workaround than this with blank printf()?

Sorry fot ignorance,
--peter.

--
Peter A Cejchan
biologist
Acad. Sci., Prague, CZ
<cej at cejchan dot gli dot cas dot cz>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [9fans] APE question
@ 2001-10-12 14:14 presotto
  0 siblings, 0 replies; 10+ messages in thread
From: presotto @ 2001-10-12 14:14 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 53 bytes --]

Put an fflush(stdout) twixt the printf and getchar?

[-- Attachment #2: Type: message/rfc822, Size: 1864 bytes --]

From: pac <cej@cejchan.gli.cas.cz>
To: 9fans@cse.psu.edu
Subject: [9fans] APE question
Date: Fri, 12 Oct 2001 16:21:26 +0200
Message-ID: <cej-1011012162124.A01246@cejchan.gli.cas.cz>

Friends,

under APE, the following part of code:

                printf("\nQuit [q], confirm [y], or change [menu] settings: ");               
                /* read one char */
                ch = getchar();
 
does not print out the message before waiting for a character input, unless it is flushed
e.g. by adding 
	printf("\n");
before line 3. Is this an intention? If so, could you tell me a better workaround than this with blank printf()?

Sorry fot ignorance,
--peter.

--
Peter A Cejchan
biologist
Acad. Sci., Prague, CZ
<cej at cejchan dot gli dot cas dot cz>

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2001-10-15  9:11 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-12 14:21 [9fans] APE question pac
  -- strict thread matches above, loose matches on Subject: below --
2001-10-12 14:33 pac
2001-10-12 14:34 ` Boyd Roberts
2001-10-12 14:40 ` Laura Creighton
2001-10-12 14:45 ` Howard Trickey
2001-10-12 14:58   ` Howard Trickey
2001-10-15  4:20     ` pac
2001-10-15  9:11 ` Douglas A. Gwyn
2001-10-12 14:32 rog
2001-10-12 14:14 presotto

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).