diff options
Diffstat (limited to 'nl/string_index.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; } |