title: C - AND operator between two arrays
body: <p>I want to subsample an array based on a true-false vector:</p>
  
  <pre><code>array1 - ughIuytLikeretC
  
  array2 - ffftfffttttffft
  </code></pre>
  
  <p>Such that <code>array1 &amp;&amp; array2</code> yields:</p>
  
  <pre><code>array3 - ILikeC
  </code></pre>
  
  <p>What I have done:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdbool.h&gt;
  
  int main() {
  
      char source[16] = "ughIuytLikeretC\0";
      bool mask[15] = {
          false, false, false, true, false,
          false, false, true, true, true,
          true, false, false, false, true,
      };
      char *filtered;
      filtered = malloc(16 * sizeof(char));
  
      int j = 0;
      int i;
      for (i = 0; i &lt; 15; i++) {
          if (mask[i]) {
              filtered[j] = source[i];
              j += 1;
          }
      }
      filtered[j] = 0;
      printf("%s\n", filtered);
      free(filtered);
  }
  </code></pre>
  
  <p>My questions are:<br>
  Is this an OK way of doing it or is there a sleeker way of achieving this? </p>