tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
23
Task/Reverse-a-string/XPL0/reverse-a-string.xpl0
Normal file
23
Task/Reverse-a-string/XPL0/reverse-a-string.xpl0
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
include c:\cxpl\codes; \intrinsic 'code' declarations
|
||||
string 0; \use zero-terminated strings, instead of MSb terminated
|
||||
|
||||
func StrLen(Str); \Return the number of characters in an ASCIIZ string
|
||||
char Str;
|
||||
int I;
|
||||
for I:= 0 to -1>>1-1 do
|
||||
if Str(I) = 0 then return I;
|
||||
|
||||
func RevStr(S); \Reverse the order of the bytes in a string
|
||||
char S;
|
||||
int L, I, T;
|
||||
[L:= StrLen(S);
|
||||
for I:= 0 to L/2-1 do
|
||||
[T:= S(I); S(I):= S(L-I-1); S(L-I-1):= T];
|
||||
return S;
|
||||
];
|
||||
|
||||
[Text(0, RevStr("a")); CrLf(0);
|
||||
Text(0, RevStr("ab")); CrLf(0);
|
||||
Text(0, RevStr("abc")); CrLf(0);
|
||||
Text(0, RevStr("Able was I ere I saw Elba.")); CrLf(0);
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue