tags:

views:

126

answers:

3
A: 

This is what i think

You are trying to read 'yhgf' into an integer (gr_sk), so when read reads, it throws an error because 'yhgf' can't be transformed into an integer.

What should you do?

Well, I think that you can read it into a string, validate that it is a number, and then transform it into an integer. Frankly, I don't remember the Pascal way to do it. After googling around, found val procedure.

Val converts the integer or real number that is represented by the characters in the string Source and places it into x.

Some tips on string functions / procedures:

Tom
A[id].name is a string, so yhgf should work!
hey
It reads the whole sentence, there was a problem.
hey
A: 

I have many years to use old Pascal (nowadays I use Delphi), and I think you are using your c variable wrongly. Anyway, in Pascal you can declare file variables and associate a record type on them.

Example:

  type info ...

  var f: file info; { <-- here }
  ...

  begin
     assign(f, 'info.txt');
     reset(f);
     id := 1;
     read(f, A[id]);
     close(f);
  { now A[1] should contain file data }
  ...
Nick D
I forgot to mention that `info.txt` should be created programatically, ie `assign(f,'...');` `write(f, A[1]);` if you use my example. Actually, it won't be a "text" file anymore :-P
Nick D
A: 

Change

read(c, A[id].name);

to

readln(c, A[id].name);

Anyway I would search the problem in that direction; namely the not reading of the lineseparator. (CR and LF)

When in doubt, do a read(f,) and write the ORD() of a few of the read chars to screen

Marco van de Voort