Click here to Skip to main content
15,887,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, well i've been trying to make a program a program that will read from a text file the first num. of the firs line, and then will do a certain procedure, that means a procedura that will read the other nums. into arrays, as many times as the value of the first num is. This is the program i've made, but the compiler has errors. Is that possibly because i have not put in every procedure a for i:=1 to n do or for i:=1 to 100000 do?
Can anyone please help me?
Program filetext;
Var
a:array[1..100000] of integer;
b:array[1..100000] of integer;
c,d,i,j:Integer;
f:Text;
Procedure thenum ;
Begin
repeat
Read (f,a[i]);
Write(a[i]);
until (a[i]=' ');
End;

Procedure sth ;
begin
while not seekEoln and eof(f) do
begin
read(f,j[i]);
Write(j[i]);
end;
End;
Procedure theprogram;
thenum;
space;
sth;

procedure space;
begin
Reset(f);
Read(f,c);
Write(c);
end;

begin
Assign(f,'textfile.txt');
Reset(f);
repeat
Read (f,n);
Write(n);
until (n=' ');
End;

Read(f,c);
Write(c);
while not seekEoln and eof(f) do
begin
read(f,d);
Write(d);
end;
for i:=1  to n do
theprogram;
Close(f);
Readln;
End.
Posted

1 solution

You should report the exact error messages, on order to get help.
I tried to compile it with Free Pascal Compiler, getting:
filetext.pas(12,13) Error: Incompatible types: got "Char" expected "Int64"
filetext.pas(19,10) Error: Illegal qualifier
filetext.pas(20,9) Error: Illegal qualifier
filetext.pas(24,1) Fatal: Syntax error, "BEGIN" expected but "identifier THENUM" found




First error reports a type mismatch: you cannot compare integers to characters:
Quote:
until (a[i]=' ');
You could fix it, for instance this way (if it makes sense to you)
until (a[i]=-1);



Second (and third) error occurs because you are using an integer like an array.
Quote:
read(f,j[i]);
Write(j[i]);
You cannot subscript a integer variable (an array is required).


Fourth error: BEGIN is required: you forgot to put BEGIN immediately below the
Quote:
Procedure theprogram;
line.
 
Share this answer
 
Comments
Member 10538783 25-Jan-14 4:40am    
Thanks for your help, i corrected the last error with the procedure, but the problem with the illegal qyalifier, espesially in procedure the num, is that it must read until the space, and the text that reads from the variable, must have in each line only two nums., that are seperated by only a space, so anything is there anything i could do?
CPallini 25-Jan-14 5:36am    
I guess (I am not a Pascal expert) you might, for instance, handle the exception thrown when reading the integer fails.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900