title: C : Pass Array of string as function argument
body: <p>So what I have is a file <strong>main.c</strong> which is including a header file I made <strong>utils.h</strong>, containing forward references to functions in my source file <strong>utils.c</strong></p>
  
  <h3>In utils.c:</h3>
  
  <p>I have a function that accepts an array of string as an argument, and prints it out as a menu:</p>
  
  <pre><code>void showMenu(const char *menu[])
  {
      int menulen = sizeof(menu)/sizeof(*menu);
  
      int i;
      for(i = 0; i &lt; menulen; i++)
      {
          printf("[%d] .. %s\n", (i+1), menu[i]);
      }
  }
  </code></pre>
  
  <h3>In main.c:</h3>
  
  <p>I simply call this function:</p>
  
  <pre><code>const char *menu[] =
  {
          "Customers",
          "Orders",
          "Products"
  };
  
  int main(void)
  {
      showTitle("Customer Orders System");
      int menulen = sizeof(menu)/sizeof(*menu);
      showMenu(menu);
      getch();
  }
  </code></pre>
  
  <h3>My Problem:</h3>
  
  <p>My <strong>showMenu</strong> function is calculating the length of the array, and then iterating through it, printing the strings. This used to work when the function was in <strong>main.c</strong>, but I am required to organize this project in separate files.</p>
  
  <p>The length is now being calculated as 1. After doing some debugging, I think this is a pointer-related problem, but I seem to resolve it. The argument for <strong>showMenu</strong> after the call is of type</p>
  
  <pre><code>const char** menu
  </code></pre>
  
  <p>having only the first element of my original array.</p>
  
  <p>I tried deferencing the argument, passing it a pointer of the array, and both at the same time.<br />
  Strangely enough, the same line of code works in the main function.
  I really don't want to have to resolve this problem by adding a length of array argument to the function.</p>
  
  <p>Any help is greatly appreciated.</p>