From ef8cf00bbf9f74eb3b6aabc1d99f5358e81741c7 Mon Sep 17 00:00:00 2001 From: thing1 Date: Tue, 1 Oct 2024 08:55:32 +0100 Subject: added some cool examples to zpy and got electronics working --- comp/lucas-standen-NEA/code2/stdlib/String/String.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'comp/lucas-standen-NEA/code2/stdlib/String/String.c') diff --git a/comp/lucas-standen-NEA/code2/stdlib/String/String.c b/comp/lucas-standen-NEA/code2/stdlib/String/String.c index 2814a1c..6f11119 100644 --- a/comp/lucas-standen-NEA/code2/stdlib/String/String.c +++ b/comp/lucas-standen-NEA/code2/stdlib/String/String.c @@ -11,6 +11,16 @@ void __stringfree(string *self){ free(self); } +void __stringprint(string *self){ + printf("%s\n", self->_str); +} + +void __stringinput(string *self, size_t len){ + char *tmp = calloc(0, len); + fgets(tmp, len, stdin); + self->fromcstring(self, tmp); +} + void __stringappendchar(string *self, char c){ self->_len++; self->_str = realloc(self->_str, self->_len); @@ -132,6 +142,8 @@ string *String(char *cstring){ // returns an allocated String from a C string in str->fromcstring = &__stringfromcstring; str->tocstring = &__stringtocstring; str->split = &__stringsplit; + str->print = &__stringprint; + str->input = &__stringinput; return str; } -- cgit v1.2.3