title: Segfault while Reading text file into structure pointer
body: <p>I am writing a code to compute jedi name which is a combination of first name and last name. I have written the entire code and getting segmentation fault in the while loop.</p>
  
  <p>Following is the code. It is divided into a header and a C file:</p>
  
  <p>Structures.h</p>
  
  <pre><code>//void jediName(char *first_name, char *last_name, char buffer[10]);
  //void jediName(struct Names Name_Param);
  //void * allocate(unsigned int size);
  //void * deallocate(void *, int size);
  
  int heap_usage = 0;
  
  struct Names{
      char *first_name;
      char *last_name;
      char *jedi_name;
  };
  
  struct Names *name;
  
  void jediName(struct Names *Name_Param);
  void * allocate(unsigned int size);
  void * deallocate(void *, int size);
  </code></pre>
  
  <p>Program.c</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  #include "Structures.h"
  
  int main(){
  
  //  char fname[10];
  //  char lname[10];
  //  char buff[10]= "";
      char buffer1[250];
      char buffer2[250];
  
      FILE * fp;
  /*
          printf("Enter the first &amp; last name : \n");
          scanf("%s %s", buffer1, buffer2 );
  
      fp = fopen("names.txt", "a");
      fprintf(fp, "\n%s %s", buffer1, buffer2);
      fclose(fp);
  */
  
      fp = fopen("names.txt","r");
      name-&gt;first_name == allocate(10);
      name-&gt;last_name == allocate(10);
      name-&gt;jedi_name == allocate(10);
  
      while(!feof(fp)){
          fscanf(fp, "%s %s", name-&gt;first_name, name-&gt;last_name);
          jediName(name);
  //      jediName(name-&gt;first_name, name-&gt;last_name, name-&gt;jedi_name);
          printf("%s %s %s", name-&gt;first_name, name-&gt;last_name);
      }
      deallocate(name-&gt;first_name, 10);
          deallocate(name-&gt;last_name, 10);
          deallocate(name-&gt;jedi_name, 10);
  
      fclose(fp);
  
      return 0;
  }
  
  /*
  void jediName(char *first_name, char *last_name, char buffer[10]){
      if(strlen(first_name)&lt;2 || strlen(last_name)&lt;3)
          printf("Name of %s %s is too short to compute a jedi name\n", first_name, last_name);
      else{
          buffer[0] = last_name[0];
              buffer[1] = last_name[1];
              buffer[2] = last_name[2];
              buffer[3] = first_name[0];
              buffer[4] = first_name[1];
              printf("Jedi Name for %s %s is %s\n", first_name, last_name, buffer);
      }
  
      return;
  }
  */
  
  void jediName(struct Names *Name_Param){
          if(strlen(Name_Param-&gt;first_name)&lt;2 || strlen(Name_Param-&gt;last_name)&lt;3)
                  printf("Name of %s %s is too short to compute a jedi name\n", Name_Param-&gt;first_name, Name_Param-&gt;last_name);
          else{
                  Name_Param-&gt;jedi_name[0] = Name_Param-&gt;last_name[0];
                  Name_Param-&gt;jedi_name[1] = Name_Param-&gt;last_name[1];
                  Name_Param-&gt;jedi_name[2] = Name_Param-&gt;last_name[2];
                  Name_Param-&gt;jedi_name[3] = Name_Param-&gt;first_name[0];
                  Name_Param-&gt;jedi_name[4] = Name_Param-&gt;first_name[1];
                  printf("Jedi Name for %s %s is %s\n", Name_Param-&gt;first_name, Name_Param-&gt;last_name, Name_Param-&gt;jedi_name);
          }
  
          return;
  }
  
  void * allocate(unsigned int size){
      heap_usage = heap_usage + size;
      printf("The current heap size after heap allocation is %d\n", heap_usage);
      void *heapMem = malloc(size);
      if(heapMem == NULL)
          printf("Pointer is NULL\n");
      else
          printf("Pointer is not NULL\n");
  
      return heapMem;
  }
  
  void * deallocate(void *heapMem, int size){
      heap_usage = heap_usage - size;
      printf("The current heap size after heap deallocation is %d\n", heap_usage);
      free(heapMem);
      heapMem = NULL;
      return NULL;
  }
  </code></pre>