Quote:
>Recently I posted:
>>I am a novice at programming in Fortran however, I have done extensive
>>programming in C. One of the funtions in C which I found useful was the
>>getchar() function. This function waits for the user to input a single
>>character (the answer to a yes/no question) without waiting for the enter
>>key. Is this possible to do in Fortran?
>>Also, is there a way that I could let the user use the function keys and the
>>arrow keys?
>In this posting, I neglected to mention the type of machine I was using, the
>operating system, and the version of FORTRAN I was using.
>I am using a PC, DOS-based machine, FORTRAN 90 and the program has no need
>for portability. I hope that this information will get more positive
>responses. Thank you to those who have responded.
Paul,
you are wrong is assuming that getchar() works as you are claiming.
Had this been true, no need would be for getche() in Borland C languages.
In fact the ANSI C standard does not explicitly state WHEN THE GETCHAR()
will return. You are only guaranteed that you will get the first char
"waiting" in stdin, but not when. So your claim about getchar() functionality
is incorrect to my knowledge. As an example try the following:
----
#include <stdio.h>
main()
{
int c;
while ((c=getchar()) != '0')
printf("\t<%d>\n", c);
Quote:
}
-----
and it won't work as you claim. (Yes I tried it on VAX, AXP and HP-RISC).
Now regarding your question: there is *no* portable way of doing this
in FORTRAN either; both FORTRAN 77 and 90 for that matter. However, the
recommended solution in these cases is to write routines of the form:
SYS_GETCHAR_ECHO() that you rewrite every time you move to another
platform. Now for PCs you will need to have a gateway routine to
the system/BIOS interrupt services. Usually such a routine has a
format:
SUBROUTINE INT86( INT_NO, REGS_IN, REGS_OUT )
Where INT_NO is the interrupt number, and REGS_IN, REGS_OUT are integer
arrays containing the values of registers at input/output. Once you
have this routine at your service you will need to find the correct
interrupt. For your needs you will need INT21h function 07h and read
the AL register on return. The register will contain the character,
or for extended key-code like the arrow keys a zero (0) in which
case you need to execute the interrupt again to get the "truly" hit
key/character. For more on this send me e-mail or get yourself a
good book on MS-DOS interrupts, or download the Ralf Brown's list
of interrupt services (available in Win HELP format and text format)
from garbo.uwasa.fi at pc/programming; I think the files start with
intxxxx or something like that.
Hope this helps a bit.
Petros Dafniotis