急!!turbo pascal file access

2013-06-29 9:34 pm
How to random access text file by using turbo pascal 7.0?

Can anyone gives me the program code?




For example


---------text file--------
1
2
3
4
4.5
6
7
--------------------------
II
v
---------text file---------
1
2
3
4
6
7
------------------------------
II
v
---------text file---------
1
2
3
4
5
6
7
-----------------------------


porgram test;
var
diskfile:text;
begin
assign(diskfile,'abc.txt');
..............
close(diskfile);
end;

I had only learn pascal.Please explain the program code in a easy way.
Answer in Chinese.
thank you
更新1:

for the first step,delete a record in text file directly for the second step,insert a record in text file directly

回答 (1)

2013-06-30 7:57 am
✔ 最佳答案
TEXT FILE因為每行長度不同,根本不能實現random access!
而且要REPLACE其中一行,更加不可能,除非你首要條件係每行必須相同長度,以RECORD來讀及寫,但如此就不必要用TEXT FILE做基本了,倒不如用BINARY FILE。
如你必要用TEXT FILE,又能做到RANDOM ACCESS,又能隨時替換某一行,最簡單方法就係啟動時把所有行讀入一個STRING ARRAY,到完成時把所有行重新寫入TEXT FILE。那替換一行資料就只要把STRINGARRAY〔X〕:=新資料就可以。刪去一行則把餘下的向上移。不在此細述了。


收錄日期: 2021-04-26 23:56:15
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20130629000051KK00111

檢視 Wayback Machine 備份