Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
25
Task/Reverse-a-string/Cowgol/reverse-a-string.cowgol
Normal file
25
Task/Reverse-a-string/Cowgol/reverse-a-string.cowgol
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
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]));
|
||||
Loading…
Add table
Add a link
Reference in a new issue