title: Circular Linked list is crashing while trying to print
body: <p>So I'm working on a program, that will eventually simulate a lame version of duck duck goose (actually called duck duck boot by the professor). When I read the problem circular linked list is what popped out towards me. Though I am very new at using linked lists in general. </p>
  
  <p>It seems like the program is creating and assigning the nodes, but I crash when I try to print them.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  typedef struct {
      char name[20];
      struct jimmysFriend *next;
  } jimmysFriend;
  
  jimmysFriend *createNode();
  void populateList(jimmysFriend *bestFriend, int numberOfFriends);
  //void duckDuckBoot();
  void printList(jimmysFriend *bestFriend);
  
  int main(void) {
      int i;
      int cases;
      int numberOfFriends;
      scanf("%d", &amp;cases);
      for (i = 0; i &lt; cases; i++) {
          scanf("%d", &amp;numberOfFriends);
          jimmysFriend *bestFriend; //head
          bestFriend = NULL;
          populateList(bestFriend, numberOfFriends);
          printList(bestFriend);
      }
      return 0;
  }
  
  void populateList(jimmysFriend *bestFriend, int numberOfFriends) {
      int i; //Where I actually create the circular list.
      jimmysFriend *aFriend;
      for (i = 0; i &lt; numberOfFriends; i++) {
          aFriend = createNode();
          if (bestFriend == NULL) {
              bestFriend = aFriend;
              aFriend-&gt;next = aFriend;
          } else
          if (bestFriend != NULL) {
              jimmysFriend *temptr;
              aFriend-&gt;next = bestFriend;
              temptr = bestFriend;
              while (temptr-&gt;next != bestFriend) {
                  temptr = temptr-&gt;next;
              }
              temptr-&gt;next = aFriend;
          }
      }
  }
  
  jimmysFriend *createNode() { //Creates a node
      jimmysFriend *aFriend;
      aFriend = malloc(sizeof(jimmysFriend));
      if (aFriend != NULL) {
          scanf("%s", aFriend-&gt;name);
      }
      return aFriend;
  }
  
  void printList(jimmysFriend *bestFriend) { //Problem area?
      jimmysFriend *temptr;
      temptr = bestFriend;
      while (temptr-&gt;next != bestFriend) {
          printf("%s\n", temptr-&gt;name);
          temptr = temptr-&gt;next;
      }
  }
  </code></pre>