title: Copy string from const char *const array to string (in C)
body: <p><strong>EDIT</strong>: I added the full code.</p>
  
  <p>I get an array with names and need them to create a string, depending of how many names exist this string looks different. I tried to concatenate the strings with strcpy and strcat but it doesn't work. </p>
  
  <pre><code>char* function1 (size_t n, const char *const names[n]) {
      char *res;
  
      switch (n) {
      case 0:
          res = "no one likes this";
          break;
  
      case 1:
          strcpy(res, names[0]);
          strcat(res, " likes this");
          break;
  
      case 2:
          strcpy(res, names[0]);
          strcat(res, " and ");
          strcat(res, names[1]);
          strcat(res, " like this");
          break;
  
      case 3:
          strcpy(res, names[0]);
          strcat(res, ", ");
          strcat(res, names[1]);
          strcat(res, " and ");
          strcat(res, names[2]);
          strcat(res, " like this");
          break;
  
      default:
          strcpy(res, names[0]);
          strcat(res, ", ");
          strcat(res, names[1]);
          strcat(res, " and ");
          strcat(res, (char*) (n - 2));
          strcat(res, " others like this");
          break; 
     }
     return res;
  }
  </code></pre>
  
  <p>How can I get the names from the array? Do I have to get the length of each name and then copy each char by char?</p>
  
  <p>The function is called as follow:</p>
  
  <pre><code>int main(void) {    
     const char *const names[3] = {"John", "Peter", "Paul"};
     char* res = function1(3, names);
     printf("%s", res);
  
     return 0;
  }
  </code></pre>
  
  <p>The result should be as follows:</p>
  
  <ul>
  <li>1 name:     X likes this. </li>
  <li>2 names:    X and Y like this. </li>
  <li>3 names:    X, Y, and Z like this. </li>
  <li>4 and more: X, Y and 'number' more like this.</li>
  </ul>
  
  <p>I know how to concat the strings, but struggling to copy the names out of the array. This is from a C exercise in a tutorial.</p>