title: C Programing pthread print segmentation fault
body: <p>Below is my code. I'm trying to get the <code>main_thread</code> to get user input, store in <code>global_variable</code>, then print out. However, after getting the input, my print out is Segmentation Fault. Anyone got any ideas?</p>
  
  <pre><code>#include &lt;string.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;pthread.h&gt;
  
  char* global_variable;
  
  void *first_thread(void *ptr) {
      printf("%s \n", (char *)ptr);
      pthread_exit(NULL);
  }
  
  void *second_thread(void *ptr) {
      printf("%s \n", (char *)ptr);
      pthread_exit(NULL);
  }
  
  void *third_thread(void *ptr) {
      printf("%s \n", (char *)ptr);
      pthread_exit(NULL);
  }
  
  void *main_thread() {
  
      printf("Thread 1: Please enter a line of text [Enter \"Exit\" to quit]\n");
      fgets(global_variable, 999, stdin);
      printf("%s", global_variable);
  
      pthread_exit(NULL);
  }
  
  int main () {
  
      pthread_t t_m, t1, t2, t3;
  
      //const char *m1 = "Thread 1", *m2 = "Thread 1", *m3 = "Thread 3";
  
      int cr1, cr2;
  
      //creating threads
      cr1 = pthread_create(&amp;t_m, NULL, main_thread, NULL);
      //cr1 = pthread_create(&amp;t1, NULL, first_thread, NULL);
      //cr1 = pthread_create(&amp;t2, NULL, second_thread, NULL);
      //cr1 = pthread_create(&amp;t3, NULL, third_thread, NULL);
      //threads created
  
      pthread_join(t_m, NULL);
  
      printf("Global Variable: %s", global_variable);
  
      exit(0);
      return 0;
  }
  </code></pre>