Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Fortran: Word input rather than number?

  1. Sep 3, 2011 #1
    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
     
  2. jcsd
  3. Sep 3, 2011 #2

    uart

    User Avatar
    Science Advisor

    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 (Text):

    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 ==
     
  4. Sep 4, 2011 #3
    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
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Fortran: Word input rather than number?
  1. Fortran Input File (Replies: 1)

Loading...