4 Replies - 1359 Views - Last Post: 30 January 2008 - 07:35 AM Rate Topic: -----

#1 Cobok  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 31
  • Joined: 18-March 07

Free Pascal Serious Problem

Posted 30 January 2008 - 03:40 AM

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:
$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 January 2008 - 03:41 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Free Pascal Serious Problem

#2 Cobok  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 31
  • Joined: 18-March 07

Re: Free Pascal Serious Problem

Posted 30 January 2008 - 03:56 AM

Can't Anyone help?
Was This Post Helpful? 0
  • +
  • -

#3 jjhaag  Icon User is offline

  • me editor am smartastic
  • member icon

Reputation: 45
  • View blog
  • Posts: 1,789
  • Joined: 18-September 07

Re: Free Pascal Serious Problem

Posted 30 January 2008 - 04:47 AM

The members here provide assistance on a volunteer basis. We try to provide quick answers whenever we can, but jobs, school, family, sleep and other things often have to take priority, despite the hard-core committment and dedication that many here demonstrate.

But bumping a post after 16 minutes is just ridiculous.

If you have that much of a time constraint with this, you may want to take a look at the live programming help links on the various pages here.
Was This Post Helpful? 0
  • +
  • -

#4 Cobok  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 31
  • Joined: 18-March 07

Re: Free Pascal Serious Problem

Posted 30 January 2008 - 04:55 AM

View Postjjhaag, on 30 Jan, 2008 - 04:47 AM, said:

The members here provide assistance on a volunteer basis. We try to provide quick answers whenever we can, but jobs, school, family, sleep and other things often have to take priority, despite the hard-core committment and dedication that many here demonstrate.

You are quite right ,and I'm sorry for the double post ...
I just wondered if I had written something stupid so that nobody Could really help...
So , in this way ,I was looking for someone to say , we can't help because ... e.t.c. :rolleyes:
Was This Post Helpful? 0
  • +
  • -

#5 Cobok  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 31
  • Joined: 18-March 07

Re: Free Pascal Serious Problem

Posted 30 January 2008 - 07:35 AM

Ok, solved it , for those of you that want to know , here is the fixed code
Program Lesson9_Program1;

Uses Crt;

Var
	UserFile, Wfile : Text;
	 tmp ,tmp1 : String;
	len, g, i, j, f, t : Integer;
	Gram :array[1..25] of String;
	Cram :array[1..25] of Integer;
	TFile :Char;





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] := ' ';
{-------------------------------------------------------------ARRAYS PREPARED}

 Assign(UserFile, 'friktories.in');
 Reset(UserFile);

  While not eof(Userfile) do
  Begin
  Read(UserFile,TFile);
  tmp:=Tfile;


	For j := 1 to 25 do
	 Begin
	 If Gram[j]=tmp then
	 Cram[j]:=Cram[j] + 1;
	 end;

  End;

 Close(UserFile);
{------------------------------------------------------TRYING TO READ THE FILE}




 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,'friktories.out');
 Rewrite(Wfile);

for i:=1 to 25 do
writeln(Wfile, Gram[i], ' ', Cram[i], ' ');

close(wfile);

End.




Was This Post Helpful? 0
  • +
  • -

Page 1 of 1