Program:
program s;
type
info = record
name, surname: string;
min, sek: integer;
end;
type arrays = array[1..50] of info;
var
c, b: text;
A: arrays;
gr_sk, grup_dal: integer;
begin
assign(c, 'info.txt');
reset(c);
read(c, gr_sk);
read(c, grup_dal);
id := 1;
read(c, A[id].name);
read(c, A[id].sek);
close(c);
end.
info.txt file:
3
4
yhgf
4
Please, tell me what is wrong with that. It says that it is bad number format for line 19 I guess.
If I change min, sek: integer; to min, sek: string; then it works. So as I understand, it reads number like string. How can it be? I have never experienced that before.
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.
Some tips on string functions / procedures: