[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: apple II and text files



In article <93099.122647F0O@psuvm.psu.edu> <F0O@psuvm.psu.edu> writes:
>   I was trying to write a program today which would read in a line of
>text and then append it to another file.  What I found out seems to be
>that you can't both read and write at the same time, as if there is
>only one buffer in the apple which is used for both input and output.
>If this is true, this is bizarre!  Am I doing something wrong, or do
>you have to read then close, write and close, then repeat the cycle?

Hmm...sounds like you're programming in BASIC.

Yes, it's true...BASIC can't read and write files at the same time--the
reason is that a DOS command (*ANY* DOS command) will turn off a read or a
write.  Thus, if you've got a read going, and you PRINT D$;"WRITE...",
you'll turn off the read.  Here's the way you need to do it:

     OPEN both files
     repeat
          PRINT D$;"READ RFILE"
          input stuff
          PRINT D$;"WRITE WFILE"
          print stuff
     until you're done
     CLOSE both files

>   Also, how reliable is the append function?  I appended some data to
>what was supposed to be a blank file, but after appending there was
>some junk at the beginning.  Are there any gotchs to writing and reading
>text files?

The reliability of APPEND depends on which operating system you're using.
The ProDOS APPEND command is supposed to be pretty reliable.  The DOS 3.3
APPEND command has an obscure bug in it which, under the right combination
of bizarre circumstances, can cause the writing to start at the wrong
place.

               - Neil Parker
--
Neil Parker                 No cute ASCII art...no cute quote...no cute
nparker@cie.uoregon.edu     disclaimer...no deposit, no return...
parker@corona.uoregon.edu   (This space intentionally left blank:           )