pascal 在文件不为空时跳过文件 [英] pascal skips file whilst it is not empty

查看:53
本文介绍了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.

这篇关于pascal 在文件不为空时跳过文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆