From 9b27c07a9cd275b61d0908aca1bc9c45b332e059 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Fri, 11 Dec 2020 13:06:50 -0500 Subject: [PATCH] added strmcat --- lib/a/strmcat.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 lib/a/strmcat.c diff --git a/lib/a/strmcat.c b/lib/a/strmcat.c new file mode 100644 index 0000000..1cefc62 --- /dev/null +++ b/lib/a/strmcat.c @@ -0,0 +1,32 @@ +#include + +char* strmcat(char* first, ...) +{ + va_list args; + /* calculate the length of the final string */ + size_t len = strlen(first); + va_start(args, first); + for (char* s = NULL; (s = va_arg(args, char*));) + { + len += strlen(s); + } + va_end(args); + /* allocate the final string and copy the args into it */ + char *str = malloc(len+1), *curr = str; + while (first && *first) + { + *(curr++) = *(first++); + } + va_start(args, first); + for (char* s = NULL; (s = va_arg(args, char*));) + { + while (s && *s) + { + *(curr++) = *(s++); + } + } + va_end(args); + /* null terminate and return */ + *curr = '\0'; + return str; +} -- 2.52.0