Hi, the code below results in "0" in variable "Shrt":
Code: Select all
var Shrt: short;
S1, S2: string[10];
...
S1 := '1235';
S2 := '1236';
Shrt := StrCmp(S1, S2);
Thanks in advance!
p.s. code was compiled for P16F877A
#1 Post by Dany » 19 Apr 2009 12:38
Code: Select all
var Shrt: short;
S1, S2: string[10];
...
S1 := '1235';
S2 := '1236';
Shrt := StrCmp(S1, S2);
#2 Post by Dany » 19 Apr 2009 15:08
Code: Select all
var Shrt: short;
S1, S2: string[10];
I: word;
...
I := 0;
while (S1[I] > 0) and (S2[I] > 0) and (S1[I] = S2[I]) do
begin
Inc(I);
end;
#3 Post by srdjan » 21 Apr 2009 10:43
Dany wrote:H, I did try to write my own code for StrCmp for a 16F877A and it did also not work.
The reason is that expressions like the one below are not correctly executed:No matter if S1 differs from S[2] or not, the while loop is executed as long one of both chars is not zero.Code: Select all
var Shrt: short; S1, S2: string[10]; I: word; ... I := 0; while (S1[I] > 0) and (S2[I] > 0) and (S1[I] = S2[I]) do begin Inc(I); end;
Expression "S1 = S2" returns always true apparently. After some investigations it seems that "S1 < S2" and "S1 < S2" always return false.
Thanks in advance!
p.s. for P18 this type of code is executed correctly.
Return to “mikroPascal PRO for PIC Beta Testing”