To close a file, you simply use the function "fclose" with the file pointer in the parentheses. Actually, in this simple program, it is not necessary to close the file because the system will close all open files before returning to DOS. It would be good programming practice for you to get in the habit of closing all files in spite of the fact that they will be closed automatically, because that would act as a reminder to you of what files are open at the end of each program.
You can open a file for writing, close it, and reopen it for reading, then close it, and open it again for appending, etc. Each time you open it, you could use the same file pointer, or you could use a different one. The file pointer is simply a tool that you use to point to a file and you decide what file it will point to.
Compile and run this program.
When you run it, you will not get any output to the monitor because it doesn’t generate any. After running it, look at your directory for a file named TENLINES.TXT and "type" it. That is where your output will be. Compare the output with that specified in the program. It should agree.
Do not erase the file named TENLINES.TXT yet. We will use it in some of the other examples
in this chapter.
You can open a file for writing, close it, and reopen it for reading, then close it, and open it again for appending, etc. Each time you open it, you could use the same file pointer, or you could use a different one. The file pointer is simply a tool that you use to point to a file and you decide what file it will point to.
Compile and run this program.
When you run it, you will not get any output to the monitor because it doesn’t generate any. After running it, look at your directory for a file named TENLINES.TXT and "type" it. That is where your output will be. Compare the output with that specified in the program. It should agree.
Do not erase the file named TENLINES.TXT yet. We will use it in some of the other examples
in this chapter.