title: Global pointer to local pointer array
body: <p>I have an array of pointers to arrays, in a function. I need to access that array in another function. </p>
  
  <p>Pointer array</p>
  
  <pre><code>char *ptr[size + 1];
  </code></pre>
  
  <p>I made a global pointer </p>
  
  <pre><code>char *p;
  </code></pre>
  
  <p>which i pointed to ptr  (in the same function as ptr)</p>
  
  <pre><code>p = *ptr;
  </code></pre>
  
  <p>then i tried to access ptr from the other function</p>
  
  <pre><code>void otherFunction(void){
      for(int n = 0; n &lt; 6; n++)
      {
          char* str = &amp;p[n];
          printf("%i %s\n", n, str);
      }
  }
  </code></pre>
  
  <p>when </p>
  
  <pre><code>ptr[0] = "abcd"
  ptr[1] = "bcde"
  ptr[2] = "cdef"
  ptr[3] = "defg"
  ptr[4] = "efgh"
  ptr[5] = "fghi"
  </code></pre>
  
  <p>the output of <code>otherfunction();</code> is:</p>
  
  <pre><code>0 abcd
  1 bcd
  2 cd
  3 d
  4 
  5 
  </code></pre>
  
  <p>I want the output to be</p>
  
  <pre><code> 0 abcd
   1 bcde
   2 cdef
   3 defg
   4 efgh
   5 fghi
  </code></pre>
  
  <p>My questions are: (0) whats going wrong here. (1) How do i fix it (2) Or is there a better way to do this.  the requirements are <code>otherfunction()</code> cant take any arguments and <code>ptr</code> needs to remain local to its function. (Im certain the other code is not contributing to the problem and nothing is wrong with <code>ptr</code>)</p>