title: Is there any way to make my function return a dynamic array?
body: <p>So at the moment I have a function I made returning a static array, is there any way to make it return a dynamic array for the sake of efficiency?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include "header.h"
  
  int *charpos(char *str, char ch)
  {
      int *bff, bc, ec, i, strln;
      static int ret[255];
      bc = 0;
      ec = 0;
  
      for(i = 0; str[i] != '\0'; i++)
          ;
  
      strln = i;
      for(i = 0; i &lt;= strln; i++)
      {
          if(str[i] == ch)
              ec++;
      }
  
      bff = malloc(sizeof(int)*ec);
      if(sizeof(bff) &gt; sizeof(ret))
      {
          free(bff);
          return 0;
      }
  
      for(i = 0; i &lt;= 255; i++) ret[i] = '\0';
      for(i = 0; i &lt;= strln; i++)
      {
          if(str[i] == ch)
          {
              ret[bc] = i;
              bc++;
          }
      }
  
      free(bff);
      return ret;
  }
  </code></pre>