Turing Logo  

Designed for computer science instruction, Turing is simply the easiest, most fun, and most effective way of teaching programming concepts.


Quick Links
Home page of Holt Software Associates  | Home page of the Turing Programming Language, the fastest way to teach programming concepts  | Home page of Holt Software's Java products  | Home page of Ready to Program with Java(tm) Technology, a Java development environment designed for education  | Information about Holt Software's courses for teachers  | Information about how to contact Holt Software  | Information about how students can purchase Holt Software's books and software  | Information about how schools and bookstores can purchase Holt Software's books and software

How do I append to a file in Turing?


First, a small review of the open statement. The open statement looks like this:

open: fileNumber, fileName, capability {,capability}

fileNumber an integer variable that is assigned the stream number by this statement.
fileName the string containing the name of the file to be opened.
capability this is one of : read, write, put, get, seek or mod.
read & write used to read or write binary data to the file. Essentially, these capabilities allow the program to use the read & write statements on the file.
put & get used to read or write text data to the file. Like read & write, they allow the use of put & get statements by the program.
seek allows the use of the seek and tell statements on the file.
mod tells Turing not to erase the file if it is opened for output. Normally, a file opened for put or write is created if it doesn't exist or erased and created again if it does. mod prevents the file from being erased.

Thus, you append to a file by opening the file for put or write with the mod and seek attributes and then doing a seek to the end of file. Any put's or write's following will be added to the end of file.

To add "Hello" to the end of the file "test"

        var fileNumber: int
        open: fileNumber, "test", put, seek, mod
        seek: fileNumber, *             % seek to eof
        put: fileNumber, "Hello"
  

[ Turing Home ] * [ Top of Page ] * [ Feedback ]