title: Passing a local static array to a function
body: <p>I'm trying to pass a local array from a function <code>letter_remover</code>, which reads an original array, removes vowels + h, w and y, then copies that into a new array. This new array is then passed to main. </p>
  
  <p>For example input <code>plutonium</code> would become <code>pltnm</code>. However when I call the function in main and print out the new array, it will duplicate some letters, for instance <code>plltnm</code> is printed.</p>
  
  <pre><code>void array_filler (char a[]);
  char * letter_remover (char b[]);
  
  int main (void)
  
  {
  char name[MAX];
  char *p;
  int i;
  array_filler(name);
  p = letter_remover(name);
  printf("Local array passed back: ");
  for (i = 0; i &lt; MAX; i++)
      {
      printf("%s", p);
      p++;
      }
  
  return 0; 
  
  }
  </code></pre>
  
  <p>If I print the new array created in the function <code>letter_remover</code>, it prints correctly. The letter_remover function creates the new array as a static char[] array and returns a char *</p>
  
  <p>array_filler contains:</p>
  
  <pre><code>void array_filler (char a[])
  
  {
  printf("Type name: ");
  int i = 0, c;
  while ((c = getchar()) != '\n')
      {
          c = tolower(c);
          if (isalpha(c))
              {
                  a[i] = c;
                  i++;
              }
      }
  a[i] = '\0';
  printf("Name inside array: %s\n", a);
  
  }
  </code></pre>
  
  <p>letter_remover contains:</p>
  
  <pre><code>char * letter_remover (char b[])
  
  {
  
  int i;
  static char c[MAX];
  char a[] = "aeiouywh";
  printf("Name without forbidden characters: ");
  for (i = 0; b[i] != '\0'; i++)
  {
      if (!strchr(a, b[i]))
      {
          c[i] = b[i];
          printf("%c", c[i]);
      }
  }
  c[i] = '\0';
  printf("\n");
  return c;
  }
  </code></pre>