虽然(不是eof(inputFile))确实开始 新(newNode); read(inputFile,newNode ^ .student.index); read(inputFile,temp); newNode ^ .student.forename:=’’; read(inputFile,temp);…
在你的代码中, temp: char; 用于一次保存一个字符,从文件中读取。由于名字和姓氏由文件中的空格分隔,因此您需要检测该空格,以便将读取的字符分配给学生记录的正确字段。
temp: char;
如果 temp 将被宣布为,例如, string ,整行(索引之后)将被读入 forename 领域。
temp
string
forename
阅读名字的注释细分如下:
newNode^.student.forename := ''; // clear the forename field read(inputFile, temp); // read one character while (temp <> ' ') do begin // while the read character is not a space newNode^.student.forename:=newNode^.student.forename+temp; // concatenate with the field content read(inputFile, temp); // read next character end; // continue with rest of code when a space after the forename is detected
我不明白你的最后一个问题 read(temp) 。显示的代码中没有这样的行。如果你认为它是多余的,删除它,看看会发生什么。请务必了解如何在调试器中单步执行运行代码。
read(temp)