Kebie
10-10-2002, 04:42 AM
I am not a very strong problem, so you may see this error quickly.
Anyways I have to make a program in Delphi that reads in a bunch of words from a textfile, then compares them to an entered word, making all possible combinations with the word in the entered word.. Basicaly think about a Scrabble/Boggle Cheater.
Anyways I keep getting some access violation error then it spits back to the line where I compare character to character in this function. This is the function that compares both words to eachother and returns "true" if all the words in the dictionary word are in the entered word.
Someone told me it was in an infinate loop but they couldn't see where, and neither can I. If you can see the problem please tell me.
function CompareWord(EnteredWord :string; DictionaryWord :string): Boolean;
var
i : integer; // counter for DictionaryWord
p : integer; // counter for EnteredWord
FoundLetters : integer; //number of letters found that are the same in dictionary word compaired to the entered word.
begin
FoundLetters := 0;
if length(DictionaryWord) > length(EnteredWord) then
Result := false;
for i := 0 to length(DictionaryWord) do
begin
for p := 0 to length(EnteredWord) do
begin
if EnteredWord[p] = DictionaryWord[i] then
begin
EnteredWord[p] := '*';
inc(FoundLetters);
end;
end;
end;
if (FoundLetters MOD length(DictionaryWord)) = 0 then
Result := true
else
Result := false;
end;
Anyways I have to make a program in Delphi that reads in a bunch of words from a textfile, then compares them to an entered word, making all possible combinations with the word in the entered word.. Basicaly think about a Scrabble/Boggle Cheater.
Anyways I keep getting some access violation error then it spits back to the line where I compare character to character in this function. This is the function that compares both words to eachother and returns "true" if all the words in the dictionary word are in the entered word.
Someone told me it was in an infinate loop but they couldn't see where, and neither can I. If you can see the problem please tell me.
function CompareWord(EnteredWord :string; DictionaryWord :string): Boolean;
var
i : integer; // counter for DictionaryWord
p : integer; // counter for EnteredWord
FoundLetters : integer; //number of letters found that are the same in dictionary word compaired to the entered word.
begin
FoundLetters := 0;
if length(DictionaryWord) > length(EnteredWord) then
Result := false;
for i := 0 to length(DictionaryWord) do
begin
for p := 0 to length(EnteredWord) do
begin
if EnteredWord[p] = DictionaryWord[i] then
begin
EnteredWord[p] := '*';
inc(FoundLetters);
end;
end;
end;
if (FoundLetters MOD length(DictionaryWord)) = 0 then
Result := true
else
Result := false;
end;