Writing to a file isn't any more difficult than reading from one. Suppose that you'd like to write a program to read an integer ``N'' from the keyboard and then write the numbers 1 through N to a file. Take a look at ``file3.f'' in your ``examples'' directory (or view it directly).
The program in this file does just this, except that it writes its output to the display. Run it to see how it works.
Now compare ``file3.f'' to ``file4.f'' (or view it directly). What are the differences?
Again, that's the only basic difference between writing to the display and writing to a file. You simply use an OPEN statement to associate a unit number with a file. (You can use any unit number that you please.)
Before compiling and running the program, replace 'filename' with the name of the file where you actually want the output to go. Use the same filename as you did for the program ``file2.f''.
Make sure that the modified program runs properly, and then try the following experiment. Run ``file4'' to put numbers into the file, and then run ``file2'' to add up the numbers in the file. If you've set things up properly, the two programs will be communicating with each other through the file. But be careful---``file2'' expects exactly 10 numbers to be in the file, so be sure when you use ``file4'' that you put exactly 10 numbers into the file.
Be sure that you can get the two programs to cooperate with each other before moving on.
Hamlet Project