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

Re: apple II and text files



<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.

I assume that you are writing in BASIC. Under ProDOS, a program that
directly accesses the MLI can have up to 8 files open simultaneously
(and do reads and writes to them all). Under BASIC.SYSTEM you can have
up to 8 files open as well but only 1 can be currently active. Thus:

	10	D$=CHR$(4)
	20	PRINT D$;"OPEN FILE1"
	30	PRINT D$;"OPEN FILE2"
	40	ONERR GOTO 100
	50	PRINT D$;"READ FILE1"
	60	INPUT X$
	70	PRINT D$;"WRITE FILE2"
	80	PRINT X$
	90	GOTO 50
	99	REM assume EOF on FILE1
	100	PRINT D$;"CLOSE FILE1"
	110	PRINT D$;"CLOSE FILE2"
	120	END

This will copy FILE1 to FILE2 (assuming no lines with " or ,). Changing
line 70 to PRINT D$;"APPEND FILE2" will give you the result you want.

>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?

You don't want to CLOSE the file - next time you open it you will read
line 1 again.

>   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?

Under DOS 3.3, unreliable (many bug fixes/patches in an attempt (sucessful?)
to fix it). Under ProDOS, reliable as far as I know.
-- 
David Wilson				+61 42 213802 voice, +61 42 213262 fax
Dept Comp Sci, Uni of Wollongong	david@cs.uow.edu.au