26 lines
479 B
Plaintext
26 lines
479 B
Plaintext
include "cowgol.coh";
|
|
include "strings.coh";
|
|
|
|
# Reverse a string in place
|
|
sub StrRev(s: [uint8]): (r: [uint8]) is
|
|
r := s;
|
|
var e := s;
|
|
while [e] != 0 loop
|
|
e := @next e;
|
|
end loop;
|
|
e := @prev e;
|
|
while e > s loop
|
|
var c := [s];
|
|
[s] := [e];
|
|
[e] := c;
|
|
s := @next s;
|
|
e := @prev e;
|
|
end loop;
|
|
end sub;
|
|
|
|
# Test
|
|
var buf: uint8[32];
|
|
var str: [uint8] := "\nesreveR";
|
|
CopyString(str, &buf[0]);
|
|
print(StrRev(&buf[0]));
|