next up previous
Next: Reading from a Up: Assessment Previous: Output in Fortran

Input in Fortran

We have discussed how to do basic output in Fortran. Specifically, we have seen how to use the print statement to send messages to the person at the terminal. We have also seen how to use the write statement to send output to a file. Now we will talk about how to do basic input. We will learn how to get information from the person at the keyboard, or to obtain information from a file.

The read * statement tells the computer to stop and wait for the user to type something. When the user presses the Enter key, the computer interprets what the user has completed typing. The computer then will convert the keyboard input and stores that it in the variable named in the read statement. For example, suppose that the variable count has been declared to be an integer variable. The statement:

      read *, count

tells the computer to wait for the user to type in an integer value and press the Enter key. When the user has done that, the computer takes that integer and puts it's value in the variable count. Notice that there is a comma after the star ( *) in the read statement. That comma is required. It's just like the comma after the star in the print statement. The read statement can also be used to input real numbers from the user as in the rbtjnts.f program.



next up previous
Next: Reading from a Up: Assessment Previous: Output in Fortran


J. C. Diaz