title: Interleaving function with different length strings
body: <p>I'm trying to build a function that interleaves two strings together regardless of size (Although it can be assumed to be under 100 characters) and outputs a pointer to a new string.</p>
  
  <pre><code>char* interleaved(const char* s1, const char* s2){
      char *word = malloc (sizeof (char) * 100);
      const char *p = s1;
      const char *p2 = s2;
      int i = 0;
      while(*p != '\0' || *p2 != '\0'){
          if(i%2 == 0){
              word[i] = *p;
              p++;
          }
          if(i%2 == 1){
              word[i] = *p2;
              p2++;
          }
          i++;
      }
      if(*p == '\0'){
          while(*p2 != '\0'){
              word[i] = *p2;
              p2++;
              i++;
          }
      }
      if(*p2 == '\0'){
          while(*p != '\0'){
              word[i] = *p;
              p++;
              i++;
          }
      }
      word[i] = '\0';
      return word;
  }
  </code></pre>
  
  <p>Currently it will work if both strings are the same length, eg 'dog' and 'cat' will produce 'dcoagt', but if the strings are uneven eg 'dogbird' and 'cat' I get 'dcoagtb', and if the second string is longer I just get 'dcoagt'. Something has to be wrong in my two if statements after the original while loop but I'm not sure what it is, can someone have a look and help me?</p>
  
  <p>Cheers</p>