title: (C) parsing std in into a linked list, infinite loop
body: <p>For some reason the code keeps segfaulting after the first printf at the for loop near the end. It doesnt print the 2nd printf at all, can someone point me in the right direction? I think it has to do with a problem in memory</p>
  
  <pre><code>struct node{
      char *fullString;
      char fileName[1024];
      int  lineNumber;
      char filler[1024];
      struct node *next;
  }; 
  
  int main (int argc, char *argv[])
  {
  
      char tmpstring[1024];
      /* This won't change, or we would lose the list in memory */
      struct node *head = NULL;       
      //tail
      struct node *tail = NULL;  
      /* This will point to each node as it traverses the list */
      struct node *ptr, *newnode;  
  
      while (fgets(tmpstring, 1024, stdin) == tmpstring) 
      {
        if ((newnode = (struct node *)malloc(sizeof(struct node))) == NULL) {
          fprintf(stderr,"mklist: malloc failure for newnode\n");
          exit(1);
          }
          if ((newnode-&gt;fullString = malloc(strlen(tmpstring)+1)) == NULL) {
          fprintf(stderr,"mklist: malloc failure for newnode-&gt;str\n");
          exit(1);
          }
          if (strncpy(newnode-&gt;fullString, tmpstring, strlen(tmpstring)+1) != newnode-&gt;fullString) {
          fprintf(stderr,"mklist: string copy problem\n");
          exit(1);
          }
  
        strcpy(newnode-&gt;fullString, tmpstring);
        newnode-&gt;next = NULL;
  
  //      if (3 != scanf(tmpstring, "%255s:%d:%255s", newnode-&gt;fileName, &amp;newnode-&gt;lineNumber, newnode-&gt;filler))
   //       abort();
  
        if (tail == NULL)
          head = tail = newnode;
        else {
          tail-&gt;next = newnode;
          tail = newnode;
        }
      }
  
      // Now print the list, element by element.
      for (ptr = head; ptr != NULL; ptr = ptr-&gt;next)
          printf("%s\n", ptr-&gt;fullString);
          printf("%s:%d:%s\n", ptr-&gt;fileName, ptr-&gt;lineNumber, ptr-&gt;filler);
  }
  </code></pre>