So basically as in the title. Here is what I am trying to do:
3
24 function RepeatedChar (l: char; s: string): boolean;
25 var
26 c, ordl, ords: integer; {counter}
27 begin
28 c := 0;
29 writeln(' LAUNCHED SEARCH FOR DUPLICATES ');
30 writeln('________________________________');
31 writeln('Searching for duplicates in: ', s);
32 writeln('char: ', l);
33 writeln('length: ', length(s));
34 for c := 1 to length(s) do
35 begin
36 writeln(ord(s[c]));
37 ordl := ord(l);
38 ords := ord(s[c]);
39 writeln('MATCHING: ', ordl, ' with ', ords);
40 if ordl = ords then
41 RepeatedChar := true
42 else
43 RepeatedChar := false;
44 end;
45 writeln('________________________________');
46 writeln(' ALL DONE ');
47 end;
But the function won't behave correctly and here is one of the examples:
LAUNCHED SEARCH FOR DUPLICATES
________________________________
Searching for duplicates in: umpty
char: t
length: 5
117
MATCHING: 116 with 117
109
MATCHING: 116 with 109
112
MATCHING: 116 with 112
116
**MATCHING: 116 with 116**
121
MATCHING: 116 with 121
________________________________
ALL DONE
Returned False
While here, all is good (note: it's the same string being searched):
LAUNCHED SEARCH FOR DUPLICATES
________________________________
Searching for duplicates in: umptyta
char: a
length: 7
117
MATCHING: 97 with 117
109
MATCHING: 97 with 109
112
MATCHING: 97 with 112
116
MATCHING: 97 with 116
121
MATCHING: 97 with 121
116
MATCHING: 97 with 116
97
MATCHING: 97 with 97
________________________________
ALL DONE
Returned True
Please help, I feel like I am going insane and my code turns into more spaghetti with each iteration.
Function is expected to return True when results of ord() match. But it happens only in some cases.