pascal 在文件不为空时跳过文件

问题描述:

我正在尝试使用 pascal 从 txt 文件中读取一些数据.当我使用 while 循环继续执行操作而文件尚未结束时,pascal 会忽略 while 循环并继续执行我的程序.真的不知道为什么会发生这种情况我使用的文件是一个 .txt 文件,它肯定不是空的!

I am trying to read some data from a txt file using pascal. When I use a while loop to keep doing actions whilst the file has not ended pascal ignores the while loop and proceeds to the end of my program. Don't really know why this is happening the file I am using is a .txt file which is most certainly not empty!

下面的代码

program Wiki_Lezen;

{$mode objfpc}

 TYPE wikiNew=RECORD
  naam,omschrijving:string;
 END;

  var f: file of wikiNew;
  var bestandsNaam:string;
  var wiki:wikiNew;
  var teller:integer;



begin

  writeln('Geef een bestandsnaam op');
  readln(bestandsNaam);
  ASSIGN(f,bestandsNaam);
  RESET(f);

  while not EOF(f) do
  begin
     read(f,wiki);
     writeln('wikinaam: ', wiki.naam);
     writeln('Geef een omschrijving voor wiki');
     readln(wiki.omschrijving);
     write(f,wiki);
  end;

  CLOSE(f);

  writeln;
  writeln('Om het programma te stoppen druk op <ENTER>');
  readln();
end.  

一个 wikinew 记录是 512 字节(两个短字符串,255 个字符 + 每个 1 个长度字节).

A wikinew record is 512 bytes (two shortstrings with 255 chars + each 1 length byte).

你的文件是一系列 512 字节的记录,里面有两个短字符串吗?或者您是否正在尝试阅读一般文本文件?那行不通.file of"仅用于固定大小的数据.

Is your file a series of records of 512 bytes with two shortstrings inside? Or are you trying to read a general textfile? That won't work. "file of" is for constant size data only.

您要查找的文件类型是文本,如果不允许,则需要字符文件.

The file type you are looking for is text, or if that isn't allowed, file of char is needed.