Re: Press any key to continue?




Sorry if this is a stupid question, but how do you do a "Press any key
to continue"? PAUSE will require you to type "go" while READ *
requires that you press the Enter key.

Why not just "Press RETURN to continue" ?

Because I'm working on a homework which we are supposed to translate a
program from QBX (Microsoft QuickBasic PDS 7.1) to g77. I couldn't
find a Fortran equivalent for the following line:

Do Until Len(Inkey$): Loop

It doesn't have to be a direct equivalent in code, but it should work
the same way. :)

FORTRAN does not actually even require your computer to have a
keyboard or screen. To do stuff like changing color, clearing the
screen, or getting a key without waiting for enter, you need to use
curses or conio. There is curses and conio for Linux and Windows.
You said you are using g77, so you can mix fortran and c. Here's
getting a character without enter in c:

#include <curses.h>

int main() {
int c;

initscr();

c = getch();
printf("\r\nGot character: %c.\r\n", c);

return 0;
}

To make a c function that is accessible in fortran, you put an
underscore after it like this:

void initscr_() { initscr(); }
void getch_() { getch(); }

then you can do

PROGRAM WHATEVER
CALL INITSCR
WRITE (*, '(A)' ADVANCE='NO') 'PRESS ANY KEY TO CONTINUE...'
CALL GETCH
END PROGRAM

g77 whatever.f -c
gcc cstuff.c -fno-leading-underscore -c
g77 whatever.o cstuff.o -o whatever


and that should work.


.



Relevant Pages