Sujet : What is getchar? (Was: getchar implementation without GNUishms)
De : gazelle (at) *nospam* shell.xmission.com (Kenny McCormack)
Groupes : comp.lang.awkDate : 26. Mar 2025, 07:07:19
Autres entêtes
Organisation : The official candy of the new Millennium
Message-ID : <vs05in$nf97$2@news.xmission.com>
References : 1 2 3 4
User-Agent : trn 4.0-test77 (Sep 1, 2010)
In article <
vs038p$12n0d$1@dont-email.me>,
Janis Papanagnou <janis_papanagnou+
ng@hotmail.com> wrote:
...
I don't know. - When I read 'getchar' I associated a character oriented
function like awk's 'getline'. That would mean not reading from stdin
with some I/O buffered return-terminated input but just processing the
data as Awk would read its input from stdin or using 'getline' would.
You need to maintain some state, though; here the actual read in line
which acts like a buffer in buffered OS reads.
It is an interesting question.
In strict C terms, getchar() is well-known, and well-defined and is pretty
much as you describe it. But in an AWK context, that sort of function
doesn't seem like it would ever be useful, so we should probably assume
that what most of the posters on the thread are talking about is something
more akin to getch() - which is what I assumed in my two posted solutions.
Now, in old languages, like Turbo C and Turbo Pascal, there were generally
two function with similar names): getchar() - which behaved as Janis
suggests and is there primarily for standards conformance and getch() -
which function as as I describe above. Note that in a Unix/Linux context,
doing single char input requires messing with TTY modes (which is ugly),
whereas in DOS/Windows, it comes pretty much "for free".
-- Nov 4, 2008 - the day when everything went from being Clinton's fault to being Obama's fault.