Code Comments
Programming Forum and web based access to our favorite programming groups.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.
Post Follow-up to this messageBamm wrote: > 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. the answer varies by compiler. tell us which you use (and off chance what type of dumb terminal you're using or emulating if any). -- Gary Scott mailto:garylscott@sbcglobal dot net Fortran Library: http://www.fortranlib.com Support the Original G95 Project: http://www.g95.org -OR- Support the GNU GFortran Project: http://gcc.gnu.org/fortran/index.html If you want to do the impossible, don't hire an expert because he knows it can't be done. -- Henry Ford
Post Follow-up to this messageOn Fri, 28 Mar 2008 18:33:50 -0700 (PDT), Bamm <bammster@gmail.com> wrote: >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" ? People do seem to have trouble with the "any key" anyway :-) pozdrav dig
Post Follow-up to this messageLuka Djigas wrote: > On Fri, 28 Mar 2008 18:33:50 -0700 (PDT), Bamm <bammster@gmail.com> > wrote: > > > > > Why not just "Press RETURN to continue" ? > > People do seem to have trouble with the "any key" anyway :-) I always liked 'Q' for "quit". > > pozdrav > dig -- Gary Scott mailto:garylscott@sbcglobal dot net Fortran Library: http://www.fortranlib.com Support the Original G95 Project: http://www.g95.org -OR- Support the GNU GFortran Project: http://gcc.gnu.org/fortran/index.html If you want to do the impossible, don't hire an expert because he knows it can't be done. -- Henry Ford
Post Follow-up to this message> >Sorry if this is a stupid question, but how do you do a "Press any 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. :)
Post Follow-up to this message
>
>
> 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.
Post Follow-up to this messageBamm wrote: > > 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: > Interesting exercise. The instructor has you translating from one obsolete language to another ?
Post Follow-up to this message> Interesting exercise. The instructor has you translating from one > obsolete language to another ? Yup. You can say that. :)
Post Follow-up to this messageBamm wrote: > > 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. :) I think you might be able to use the getchar() function from the C library. print *,'Press any key to continue...' call getchar() print *, 'Done' end You will need to compile with a special option, i.e. g77 -fno-underscoring whatever.f
Post Follow-up to this message> I think you might be able to use the getchar() function from the C library. > > print *,'Press any key to continue...' > call getchar() > print *, 'Done' > end > > You will need to compile with a special option, i.e. > g77 -fno-underscoring whatever.f I'm sorry it didn't help. It was still asking for an Enter after any key was pressed. :(
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.