title: Add to end of a single linked list Segmentation fault C
body: <p>I'm trying to make a c application which adds elements at the end of a single linked list but I get a segmentation fault after i read the last element.</p>
  
  <p>I use function <code>addAtEndSLL()</code> to add an element at the end.</p>
  
  <pre><code>//Program to add elements at the end of a single linked list
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  //Basic declaration of a SLL
  struct singleList{
      int data;
      struct singleList *next;
  };
  
  //Add an element at the end of a SLL
  int addAtEndSLL(struct singleList **startPtr, int value){
      struct singleList *newNode;
      newNode = (struct singleList *)malloc(sizeof(struct singleList));
      if(newNode == NULL){
          printf("\nFailed to Allocate Memory");
          return;
      }
  
      newNode-&gt;data = value;
      newNode-&gt;next = NULL;
      if(*startPtr == NULL){
          *startPtr = newNode;
      } else {
          struct singleList *temp = NULL;
          temp = *startPtr;
          while(temp-&gt;next != NULL){
              temp = temp-&gt;next;
          }
          temp-&gt;next = newNode;
      }
  }
  
  int main() {
      int i, value;
      struct singleList *first = NULL, *tempS = NULL;
      tempS = first;
      for(i = 1; i &lt;= 5; i++){
          printf("\nEnter the data:");
          scanf("%d", &amp;value);
          addAtEndSLL(&amp;first, value);
      }
  
      /*****This is where I belive the segfault occurs*****/
  
      while(tempS-&gt;next != NULL){
          printf("%d", tempS-&gt;data);
          tempS = tempS-&gt;next;
      }
      return 0;
  }
  </code></pre>
  
  <p>Any help would be really appreciated.</p>