From the course: Introduction to Fortran
Unlock the full course today
Join today to access over 23,200 courses taught by industry experts.
Working with files - FORTRAN Tutorial
From the course: Introduction to Fortran
Working with files
- [Instructor] One common thing that programs need to do is remember things between executions. This is generally done by writing to and reading from files. The first thing we have to do before we can write to or read from a file is open it. And once we are done with the file, we should remember to close it. Let's demonstrate this by writing an example program. In this program, we're going to ask the user for their name. But instead of saying hello and printing it to the terminal, we're going to write it into a file. So we have the variable for the user's name. The code that's going to ask them for their name, either interactively or from the command line. Now we have an open statement. The open statement needs a unit number to associate with the file, the name of the file, and in this case, a status argument with the value replace. This says that if the file already exists, we're going to go ahead and replace that file…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.