kjv

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

strutil.c (466B)


      1 #include <stdlib.h>
      2 #include <string.h>
      3 
      4 #include "strutil.h"
      5 
      6 char *
      7 str_join(size_t n, char *strs[])
      8 {
      9     size_t length = 0;
     10     for (size_t i = 0; i < n; i++) {
     11         if (i > 0) {
     12             length++;
     13         }
     14         length += strlen(strs[i]);
     15     }
     16     char *str = malloc(length + 1);
     17     str[0] = '\0';
     18     for (size_t i = 0; i < n; i++) {
     19         if (i > 0) {
     20             strcat(str, " ");
     21         }
     22         strcat(str, strs[i]);
     23     }
     24     return str;
     25 }