title: static variable scope inside and outside the function
body: <p>Please notice the static variable <code>selection</code>.
  I am testing if the selection is assigned the correct char string within the different scope.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  static char* selection;
  
  static char* sel_item(char* text)
  {
      char* pch;
      char buf[80];
      strcpy(buf, text);
      pch = strtok(buf, " ");
      return pch;
  }
  
  static int display_ecnt_codes(char* text)
  {   
      char buf[80];
      strcpy(buf, text); 
      selection = sel_item(buf);
      // why if I output the selection here, the selection is random char, not the correct char "SRFPRO".
      // printf("display_ecnt_codes: %s\n", selection); 
  }
  
  int acode_prockey()
  {
      char text[] = "SRFPRO - Surface Protection (DealerProduct)";
      display_ecnt_codes(text); 
      // why if I output the selection here, it prints the correct char string "SRFPRO".
      // what's the difference between this scope and the above scope?
      printf("acode_prockey: %s\n", selection); 
  }
  
  int main ()
  {
      acode_prockey();
      // it will output SRFPRO, the first token of the char text[].
      printf("main: %s\n", selection);  
  }   
  </code></pre>
  
  <p>I am hoping someone can explain the global static varible "selection".
  When I printf it inside the function "display_ecnt_codes", it outputs the random char. If I do not printf it inside the function, it output the correct char in the main function.</p>