Page 284 - Learn to Program - Basic-256
P. 284

Chapter 18: Files – Storing Information For Later.                              Page 268


             8
             9      # move file pointer to end of file and append
             10     seek size
             11     while true
             12        input ">", l
             13        if l = "" then exit while
             14        writeline l
             15     end while
             16
             17     # move file pointer to beginning and show contents
             18     seek 0
             19     k = 0
             20     while not eof()
             21        k = k + 1
             22        print k + " " + readline()
             23     end while
             24
             25     close
             26     end
        Program 114: Append Lines to a File




               enter a blank line to close file
               >sed sed sed
               >vim vim vim
               >
               1 bar bar bar
               2 foo foo foo
               3 grap grap grap
               4 sed sed sed
               5 vim vim vim
        Sample Output 114: Append Lines to a File












                                                       © 2019 James M. Reneau (CC BY-NC-SA 3.0 US)
   279   280   281   282   283   284   285   286   287   288   289