title: A simple C exercise going wrong: Trying to return a pointer to an array of two strings
body: <p>"Return a pointer to an array of two strings. The first is the characters
     of string s that are at even indices and the second is the characters from
     s that are at odd indices"</p>
  
  <pre><code>char **parity_strings(const char *s) {
  
  char** parity = malloc(sizeof(char*) * 2);
  char even_strings[] = "";
  char odd_strings[] = "";
  int x = 0;
  int y = 0;
  
  for (int i = 0; i &lt; strlen(s); i++) {
  
      if ((i % 2) == 0) {
  
        even_strings[x] = s[i];
        x++;
      }
      else {
         odd_strings[y] = s[i];
         y++;
      }
  }
  
  parity[0] = even_strings;
  parity[1] = odd_strings;
  
  
  
  return parity;
  
  }
  
  int main(int argc, char **argv) {
      char **r = parity_strings(argv[1]);
      printf("%s %s %s", r[0], r[1], argv[1]);
      return 0;
  }
  </code></pre>
  
  <p>My logic makes sense but the output is always incorrect. For example, with input <code>ababab</code> I get back <code>ababab</code> while the expected output is <code>aaa bbb ababab</code>. What did I do wrong?</p>