Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I write a direct access file and keep the original records?

Status
Not open for further replies.

fguser

Technical User
Mar 29, 2009
4
US
Hello,

I'm writing a sequential file that has a text on the 11th line (before that there're only line brakes). The thing is that after I write the file I'm loosing the ten first characters that I had on the original text. How can I write a direct access file and keep untouchable the original records that are right below the records that has been created?

Here is the code:

PROGRAM TEST
OPEN (UNIT=10, FILE='TEST.TXT', FORM='FORMATTED', ACCESS='DIRECT',
+STATUS='OLD', RECL=3)
DO N=0, 9, 1
WRITE (10,1, REC=N+1) N, CHAR(13), CHAR(10)
END DO
CLOSE(10)
PRINT *, CHAR(13), CHAR(10)
1 FORMAT(I1,2A1)
END

The file test.txt has a text on the 11th line and the 10th first characters are being replaced by the sequence
0
1
2
3
4
5
6
7
8
9
 
You have wrote exactly what you see:
'0' CR LF '1' CR LF ... 9 CR LF - 30 charactes total.
10 empty lines (every line contains pair CR LF only ) - 20 characters total.
So you overwrote exactly 30 - 20 = 10 characters in 11th line.
And what's your problem?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top