Hi everyone !
My problem comes up at reading files in pascal . I created a code that reades from a .in file some ascii characters and then prints in an .out file the letters with descending appearence and ascending alphabetical if they appeared the same number of times. While it works flawlessly with files less than 256 characters long , with larger files I cannot get the data stored in a string.
Please help me , as this is a school project i must have ready tomorrow or at most friday and I am lost!! A couple of hours googling didn't help either...
Here is the code:
CODE
$this_var = "Program Lesson9_Program1;
Uses Crt;
Var
UserFile, Wfile : Text;
TFile, tmp ,tmp1 : String;
len, g, i, j, f, t : Integer;
Gram :array[1..25] of String;
Cram :array[1..25] of Integer;
{For i:=1 to 80 do
write(Tfile[i]);
writeln;
For i:=80 to 160 Do
write(Tfile[i]);
writeln;
For i:=160 to 240 Do
write(Tfile[i]);
writeln;
For i:=240 to 257Do
write(Tfile[i]);
writeln;}
Begin
clrscr;
For i:= 1 to 25 do
Cram[i]:=0;
For g := 1 to 24 do
Begin
Gram[g] :=char(127+g);
end;
Gram[25] := ' ';
Assign(UserFile, 'file1.in');
Reset(UserFile);
While not eof(Userfile) do
Begin
Readln(UserFile,TFile);
writeln('EKANA LOOP!!!');
End;
Close(UserFile);
len:= length(TFile);
For i:= 1 to len do
Begin
tmp := Tfile[i];
For j := 1 to 25 do
Begin
If Gram[j]=tmp then
Cram[j]:=Cram[j] + 1;
end;
End;
for i:=2 to 25 do
for j:=25 downto i do
if Cram[j-1]<Cram[j] then
begin
t:=Cram[j-1];
Cram[j-1]:=Cram[j];
Cram[j]:=t;
tmp1:=gram[j-1];
gram[j-1]:=gram[j];
gram[j]:=tmp1;
end
else if Cram[j-1]=Cram[j] then
if gram[j-1]>gram[j] then
begin
t:=Cram[j-1];
Cram[j-1]:=Cram[j];
Cram[j]:=t;
tmp1:=gram[j-1];
gram[j-1]:=gram[j];
gram[j]:=tmp1;
end;
Assign(Wfile,'file1.out');
Rewrite(Wfile);
for i:=1 to 25 do
writeln(Wfile, Gram[i], ' ', Cram[i], ' ');
close(wfile);
readln;
End.
";
This post has been edited by Cobok: 30 Jan, 2008 - 02:41 AM