🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #3676

gets() and getchar

#3676
From: Jens Andreasen
Date: Mon, 07 Aug 1995 18:52
41 lines
1878 bytes
So I thought It was easy and it was until I wanted my (supposedly) highly
portable code to show_a_message(), and_halt_until_the_user_presses_a_key()

Well, getchar() seems to be a bit on the implementation defined side and
gets() can be considered playing russian roulette :-|

And having to use implementation defined substitutes is like throwing
std.c out the window.

Is there any convention for how many chars gets will actually read, or will
it just keep on reading until the hardware ends, if say my curious cat 
decides to take a rest on the keyboard? 
                            (I'd hate to write code to kill that cat :-))

Seriously, why not make such a convention or standard? I'd suggest 256 chars 
to be sufficient for my needs, others may prefer 1k or maybe 16k...

So IMHO a solution could be to introduce a systemvariable: MAX_GETS

{
MAX_GETS = 13; /* I want twelve char max and a nullterminator */
...
MAX_GETS = 1  /* gets() waits for Enter/Return only*/
...
MAX_GETS = 0  /* gets() gets as wild and furious as ever <grin> */
}

On second thought, maybe that should just be a constant? ......
 
Or do anybody know of a workaround using getchar that won't hang this or
that odd system because of chars left in the buffer? (Remember, the cat 
*could* be part of the system). 

And while I'm at it, how about a useful thing like user_pressed_a_key()
or chars_left_in_buffer()?

Is there anything new in ISO-C on these subjects?

-
Have a nice day!
Jens M Andreasen 
Technical Details
Message-ID: <Pine.ULT.3.91.950807194041.19202A-100000@mars>
Path: arc1-ca.pugleaf.net!news.kth.se!mars!jens-and

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.kth.se!mars!jens-and
From: Jens Andreasen <jens-and@dsv.su.se>
Newsgroups: comp.std.c
Subject: gets() and getchar
Date: Mon, 7 Aug 1995 20:52:11 +0200
Message-ID: <Pine.ULT.3.91.950807194041.19202A-100000@mars>
NNTP-Posting-Host: mars.dsv.su.se
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
X-Sender: jens-and@mars