Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,480 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,718 people online right now. Registration is fast and FREE... Join Now!




Free Pascal Serious Problem

 
Reply to this topicStart new topic

Free Pascal Serious Problem

Cobok
30 Jan, 2008 - 02:40 AM
Post #1

New D.I.C Head
*

Joined: 18 Mar, 2007
Posts: 6


My Contributions
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
User is offlineProfile CardPM
+Quote Post

Cobok
RE: Free Pascal Serious Problem
30 Jan, 2008 - 02:56 AM
Post #2

New D.I.C Head
*

Joined: 18 Mar, 2007
Posts: 6


My Contributions
Can't Anyone help?
User is offlineProfile CardPM
+Quote Post

jjhaag
RE: Free Pascal Serious Problem
30 Jan, 2008 - 03:47 AM
Post #3

me editor am smartastic
Group Icon

Joined: 18 Sep, 2007
Posts: 1,789



Thanked: 2 times
Dream Kudos: 775
Expert In: C,C++

My Contributions
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.
User is offlineProfile CardPM
+Quote Post

Cobok
RE: Free Pascal Serious Problem
30 Jan, 2008 - 03:55 AM
Post #4

New D.I.C Head
*

Joined: 18 Mar, 2007
Posts: 6


My Contributions
QUOTE(jjhaag @ 30 Jan, 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.

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.gif
User is offlineProfile CardPM
+Quote Post

Cobok
RE: Free Pascal Serious Problem
30 Jan, 2008 - 06:35 AM
Post #5

New D.I.C Head
*

Joined: 18 Mar, 2007
Posts: 6


My Contributions
Ok, solved it , for those of you that want to know , here is the fixed code
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.



User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 06:47PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month