Array concatenation function is returning gibberish. : <p>This involves two functions, both of which are listed below: </p>

<pre><code>char *catw(char *s1, char sep, char *s2) 
{
  char s[strlen(s1) + strlen(s2) + 1];
  for(int i = 0; i &lt; strlen(s1); i++) {
    s[i] = s1[i]; 
  }
  s[strlen(s1)] = sep;
  for(int j = 1; j &lt;= strlen(s2); j++) {
    s[j + strlen(s1)] = s2[j]; 
  }
  char *rs = s;
  return rs;
}
</code></pre>

<p>The above function works fine, it takes two strings and concatenates them together using the character in between them. </p>

<pre><code>char *catw_arr(char *ss[], char sep)
{
  char *ar = ss[0];
  for(int i = 1; i &lt; strlen(ss); i++)
  {
    ar = catw(ar, sep, ss[i]);
    printf("%s\n", ar);

  }
  return ar;
}
</code></pre>

<p>This function, however, is the problem. It is supposed to take an array of strings, with an int that is the length of the array, and a separator, and concat all the strings together. The printf is in there because I wanted to test what was going on. </p>

<p>here's the main function I'm using:</p>

<pre><code>int main()
{
  char *abc[3] = {"a", "b", "c"};
  printf("%s\n", catw_arr(abc, 3, '/'));
  return 0;
}
</code></pre>

<p>This is what it churns out: </p>

<pre><code>a/
?ĶS?/
?ĶS?/
</code></pre>

<p>I honestly have no idea what the problem is here. I'm assuming it's concatenating the first string with the separator, but then it's running into some crap that it can't process and starts outputting gibberish. </p>
