diff options
author | tomsmeding <tom.smeding@gmail.com> | 2017-02-03 16:30:40 +0100 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2017-02-03 16:30:40 +0100 |
commit | e72a2b8e778fff230848769643a125ae995fbe58 (patch) | |
tree | 23c2aa9b0640b5c2cf57f7e035d5cb6ae33b8e19 /nl | |
parent | 8eb3171845497a1d6025a3f59c09048d1975cd12 (diff) |
Diffstat (limited to 'nl')
-rw-r--r-- | nl/string_index.nl | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/nl/string_index.nl b/nl/string_index.nl index deb4188..55bbc08 100644 --- a/nl/string_index.nl +++ b/nl/string_index.nl @@ -1,15 +1,44 @@ extern func void(i32) putchar; extern func u64(ptr(i8)) strlen; +extern func ptr(i8)(u64) malloc; + +void printnum(i32 n) { + if (n < 0) { + putchar('-'); + n = -n; + } + if (n == 0) { + putchar('0'); + return; + } + while (n > 0) { + putchar('0' + n % 10); + n = n / 10; + } +} i32 main() { ptr(i8) s = "kaas"; - ptr(i8) orig = s; - s = s + strlen(s) - 1; i32 i = 0; - while (i < strlen(orig)) { - putchar(*(s - i)); + while (i < cast(i32)(strlen(s))) { + putchar(s[i]); i = i + 1; } putchar('\n'); + + /*ptr(i32) arr = cast(ptr(i32))(malloc(4U*16U)); + arr[0] = 1; + arr[1] = 1; + i32 i = 2; + while (i < 16) { + arr[i] = arr[i-2] + arr[i-1]; + i = i + 1; + } + i = 0; + while (i < 16) { + printnum(arr[i]); + putchar(' '); + } + putchar('\n');*/ return 0; } |