•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Pascal and Delphi section within the Software Development category of DaniWeb, a massive community of 373,191 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,832 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Pascal and Delphi advertiser:
Views: 380 | Replies: 2
![]() |
•
•
Join Date: Jan 2008
Posts: 11
Reputation:
Rep Power: 1
Solved Threads: 0
Hi to all,
I have this homework with Pascal.
We have a text file that has some text in it (thetext.txt). we want to put all the words of the text and the frequency in another file without repeating the word(file name finalfile.txt).
Example:
thetext.txt has this text in it:
the quick brown fox jumps over a big brown bear that was sleeping on a big brown board.
this is how the finalfile should look.
finalfile.txt:
the 1
quick 1
brown 3
fox 1
jumps 1
over 1
a 2
big 2
bear 1
that 1
was 1
sleeping 1
on 1
board 1
-------------------------------
I tried to solve this exercise this way.
1st we read the thetext.txt letter one by one and merge them in a string. than use a linked list to keep the word and the frequency. If for instance one of the words is in the list than we raise the frequency by one otherwise we add the word to the list and set the frequency to one.
at the end we write all the elements of the list in the finalfile.txt and we're done.
BUT when i run the program i wrote it just gets stuck!
i am pasting the code so you'll see what i wrote.
Please if anyone can help me in finding the bug, i would really appreciate that.
Have a nice weekend
I have this homework with Pascal.
We have a text file that has some text in it (thetext.txt). we want to put all the words of the text and the frequency in another file without repeating the word(file name finalfile.txt).
Example:
thetext.txt has this text in it:
the quick brown fox jumps over a big brown bear that was sleeping on a big brown board.
this is how the finalfile should look.
finalfile.txt:
the 1
quick 1
brown 3
fox 1
jumps 1
over 1
a 2
big 2
bear 1
that 1
was 1
sleeping 1
on 1
board 1
-------------------------------
I tried to solve this exercise this way.
1st we read the thetext.txt letter one by one and merge them in a string. than use a linked list to keep the word and the frequency. If for instance one of the words is in the list than we raise the frequency by one otherwise we add the word to the list and set the frequency to one.
at the end we write all the elements of the list in the finalfile.txt and we're done.
BUT when i run the program i wrote it just gets stuck!
i am pasting the code so you'll see what i wrote.
Please if anyone can help me in finding the bug, i would really appreciate that.
Have a nice weekend

Program DenduridheFjale;
Uses WinCRT;
Type
str=string[15];
fjale=^liste;
liste=record
fjala:string[15];
den:integer;
tjetri:fjale;
end;
var listajone,element,org:fjale; ff,fp:text; ch:char;fj:str;
Procedure Kontrollo_listen(Var l:fjale;fj2:str);
Var tmp,tmp2,koka:fjale; c:boolean;
Begin
c:=False;
tmp:=l; koka:=l;
If tmp=nil then
Begin
new(tmp2);
tmp2^.fjala:=fj2;
tmp2^.den:=1;
tmp2^.tjetri:=tmp;
tmp:=tmp2;
l:=tmp;
dispose(tmp2);
End
else
Begin
while tmp<>nil do
Begin
If tmp^.fjala=fj2 then
Begin
tmp^.den:=tmp^.den+1;
c:=true;
End;
tmp:=tmp^.tjetri;
End;
End;
If c=false then
Begin
new(tmp2);
tmp2^.fjala:=fj2;
tmp2^.den:=1;
tmp2^.tjetri:=koka;
koka:=tmp2;
l:=koka;
dispose(tmp2);
End;
End;
Begin {Programi Kryesor}
Assign(ff,'c:\SKTP\SKTXT\tekst.txt'); Reset(ff);
Assign(fp,'c:\SKTP\SKTXT\fjaleden.txt'); Rewrite(fp);
listajone:=nil;
new(element);
fj:='';
While not eof(ff) do
Begin
While not eoln(ff) do
Begin
Read(ff,ch);
If ((ch<>'') and (ch<>' ') and (ch<>',') and (ch<>'.') and (ch<>'?') and (ch<>'!')) then
fj:=fj+ch
else
If fj<>'' then
Begin
Kontrollo_listen(listajone,fj);
fj:='';
End;
End;
Readln(ff);
End;
org:=listajone;
while org<>nil do
Begin
writeln(fp,org^.fjala,org^.den);
org:=org^.tjetri;
End;
Close(ff);Close(fp);
END.
Learning is the process whereby knowledge is created, through the tranformation of experience...
•
•
Join Date: Jun 2006
Location: Blumenau, Brazil
Posts: 67
Reputation:
Rep Power: 3
Solved Threads: 4
Olsi009, start with this changes:
You cannot call dispose after have allocated memory that you still will use - You will use than until your program has finished. So, you will need to write a procedure in order to free allocated memory at end of your program - don't forget it.
Bye
pascal Syntax (Toggle Plain Text)
Procedure Kontrollo_listen(Var l:fjale;fj2:str); Var tmp,tmp2,koka:fjale; c:boolean; Begin c:=False; tmp:=l; koka:=l; If tmp=nil then Begin new(tmp2); tmp2^.fjala:=fj2; tmp2^.den:=1; tmp2^.tjetri:=tmp; // tmp:=tmp2; l:=tmp; // dispose(tmp2); End else Begin while (tmp<>nil) and (not c) do // while tmp<>nil do Begin If tmp^.fjala=fj2 then Begin tmp^.den:=tmp^.den+1; c:=true; End; tmp:=tmp^.tjetri; End; End; If c=false then Begin new(tmp2); tmp2^.fjala:=fj2; tmp2^.den:=1; tmp2^.tjetri:=koka; l:=tmp2; // use this // koka:=tmp2; // l:=koka; // dispose(tmp2); End; End;
Bye
"It always has, at least, two ways to make one same thing. Exactly that they are certain and wrong"(Micheus)
Brazil - Blumenau
Brazil - Blumenau
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb Pascal and Delphi Marketplace
Similar Threads
- Pascal - student search program (Pascal and Delphi)
- How to get Dev-Pascal to use other files? (Pascal and Delphi)
- data files in pascal (Pascal and Delphi)
- HELP!! About assigning and reading txt files!! (Pascal and Delphi)
- Passing txt files into a programand writeln info out (Pascal and Delphi)
Other Threads in the Pascal and Delphi Forum
- Previous Thread: OnCalcField modifying its own DataSet - Error
- Next Thread: Urgent Help PLZ


Linear Mode