From 08e39eca092cffbf8a935cc31c775b9b28feafb2 Mon Sep 17 00:00:00 2001 From: justuser-31 Date: Sun, 4 May 2025 17:16:00 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B1=D0=B5=D0=B7=D1=80=D0=B0=D0=B7=D0=BC?= =?UTF-8?q?=D0=B5=D1=80=D0=BD=D0=BE=D0=B9=20=D1=81=D1=82=D1=80=D0=BE=D0=BA?= =?UTF-8?q?=D0=B8=20=D1=81=20=D0=B4=D0=B8=D0=BD=D0=B0=D0=BC=D0=B8=D1=87?= =?UTF-8?q?=D0=B5=D1=81=D0=BA=D0=B8=D0=BC=20=D0=B2=D1=8B=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=D0=BC=20=D0=BF=D0=B0=D0=BC=D1=8F=D1=82?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/string.c | 15 +++++++++++++++ libs/string.h | 20 ++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 examples/string.c create mode 100644 libs/string.h diff --git a/examples/string.c b/examples/string.c new file mode 100644 index 0000000..9027bfb --- /dev/null +++ b/examples/string.c @@ -0,0 +1,15 @@ +#include + +#include "../libs/string.h" + +int main() { + string test = strInit("Hello?"); + printf("String now: %s\n", test); + strAdd(&test, " World?"); + printf("String now: %s\n", test); + strSet(&test, "Another intresting test with string"); + printf("String now: %s\n", test); + free(test); + + return 0; +} diff --git a/libs/string.h b/libs/string.h new file mode 100644 index 0000000..dde6c47 --- /dev/null +++ b/libs/string.h @@ -0,0 +1,20 @@ +#include +#include + +typedef char* string; +string strInit(char* s) { + string str = malloc(strlen(s) * sizeof(char)); + strcpy(str, s); + return str; +} +void strAdd(string* s, char* str_new) { + *s = realloc(*s, strlen(*s) + strlen(str_new)*sizeof(char)); + strcat(*s, str_new); +} +void strSet(string* s, char* str_new) { + *s = realloc(*s, strlen(str_new)*sizeof(char)); + strcpy(*s, str_new); +} +void strCopy(string* s1, string* s2) { + strcpy(*s2, *s1); +}