1

I probably have a basic problem. I've been trying to read an array from file and AFTER that a string from standard input in Pascal language. It doesn't send an error message, it just doesn't wait 'till I write the input string on the screen. What should I do?

Here's my code:

Procedure beolvas(var x:rangsor; var n:byte; fajl:string);
var i:byte;

Begin
  Assign(input,fajl);
  Reset(input);
Readln(n);
for i:=1 to n do begin
   Readln(x[i].diak);
   Readln(x[i].atlag);
end;
close(input)
End;

Procedure beolvasnev(var s:string; x:rangsor; n:byte);
var i:byte;
Begin
Write('Kerem a diak nevet: ');
Readln(s);
End;
1
  • Never assume file access would succeed. Always check the result. Commented Nov 16, 2012 at 23:00

2 Answers 2

2

Try Assign(input, ''); (empty file name) after you've finished with the file variable, that's after you've called close(input).

Sign up to request clarification or add additional context in comments.

Comments

1

You're not telling the program from which file to read; in the absence of a file name, the program tries to read from the console, which explains you writing "it just doesn't wait till I write the input string on the screen" (shouldn't that be "it waits until I write the input string"?).

I don't know whether this is deliberate or not, but the first line of the file is expected to hold an integral value. It would be better to read from the file a string variable and then check whether the string is numerical before using it as a loop counter.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.