title: C Segmentation Fault (core dump) with linked lists
body: <p>I am using a linked list which i named word_entry. The struct for the word_entry is the following:</p>
  
  <pre><code>struct word_entry
  
  {
          char *unique_word ;
          int word_count ;
          struct word_entry *next;
          struct word_entry *prev;
  } ;
  </code></pre>
  
  <p>And this is how I am using the code:</p>
  
  <pre><code>struct word_entry *head = NULL;
  struct word_entry *curr = NULL;
  int read_file( char *file_name )
  {
          int initialized = 0;//was head initialized?
          char ch;
          FILE *file;
          struct word_entry *we = malloc(sizeof(struct word_entry));
          we-&gt;unique_word = malloc(sizeof(char));
          we-&gt;prev = NULL;
          we-&gt;next = NULL;
          char *s1 = malloc(sizeof(char));
          char *s2 = s1;
          file = fopen(file_name, "r");//opens the file
  
          if(!file){
                  return 0;//file not opened
          }else{
  
                  while((ch = fgetc(file))!= EOF){
                          if(ch &gt;= 'A' &amp;&amp; ch &lt;= 'z'){
                                  *s2++ = ch;
                                  continue;
                          }
                          if(strlen(s1)&gt;0){
                                  if(!initialized){
                                          head = malloc(sizeof(struct word_entry));
                                          curr = head;
                                          initialized = 1;
                                  }
                                  *s2 = '\0';
                                  strcpy(we-&gt;unique_word,s1);
                                  we-&gt;word_count = 1;
                                  curr = we;
                                  printf("%s\n", head-&gt;unique_word);
                                  s1 = malloc(sizeof(char));
                                  s2 = s1;
                          }
                  }
                  return 1;
          }
          return 0; //file not opened
  }
  </code></pre>
  
  <p>I am not sure why curr = head does not modify the head when I modify curr. I would like help on figuring out to how implement my code so that whenever i modify curr it also modifies the information in head.</p>