Fortran: Word input rather than number?

  • Context: Fortran 
  • Thread starter Thread starter gmcke1
  • Start date Start date
  • Tags Tags
    Fortran Input
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 3K views
gmcke1
Messages
9
Reaction score
0
I would like to input a word in the fortran command line rather than a number. For example, if I wanted to exit a program with the word 'exit' how would that be done?

Thanks for the help :D

-Glenn
 
Physics news on Phys.org
in the fortran command line
Do you really mean "command line" here, as in "command line parameter". Or are you actually inquiring about reading (and comparing) strings.

I don't think there is a way to access command line parameters in standard fortran (at least up to F95) so I assume you mean the latter.

Code:
character(20) name

print "(a$)", 'Enter your name> '
read *, name
if (name == 'uart') print *,'Cool name dude.'

The above works for me in Fortran 95 (the gnu g95 compiler). In earlier Fortran versions you might have to use .EQ. instead of ==
 
That is exactly what I was looking for. I didn't know how to use words as input for Fortran until now :DDDDDDDDDDDDDD Thank you so much.

-Glenn