title: Cannot access memory at address in C
body: <p>I've got a linked list of nodes that contain a string of characters. The program reads characters from <em>stdin</em> until it reaches a new line and once it has it puts this string of characters into the a new node of the list.</p>
  
  <p>I've done some debugging of the different steps involved in the program and can see the list of nodes being created correctly.</p>
  
  <p><img src="https://i.stack.imgur.com/trX3N.png" alt="enter image description here"></p>
  
  <p>However, the printf statement doesn't seem to do anything if I'm stepping through the code. If I don't step through and just run the code through I get:</p>
  
  <p>Cannot access memory at address 0x2e666564</p>
  
  <p>Cannot access memory at address 0x2e666564</p>
  
  <p>Cannot access memory at address 0x2e666564</p>
  
  <p>My source code is:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  typedef struct Node {
      char *string;
      struct Node *next;
  } List;
  
  List *addNode(List *currentList, char *character)
  {
      List *tempList = calloc(1, sizeof(List));
      tempList-&gt;string = strdup(character);
      tempList-&gt;next = currentList;
  
      return tempList;
  }
  
  void printList(List *currentList)
  {
      while (currentList != NULL)
      {
          printf("%s", currentList-&gt;string);
          currentList = currentList-&gt;next;
      }
  }
  
  int main ()
  {
      char currentCharacter;
      char *currentString;
      List *mainList = NULL;
  
      do 
      {
          currentCharacter = getchar();
          if (currentCharacter == '\n')
          {
              mainList = addNode(mainList, currentString);
              currentString[0] = '\0';
          } else {
              strcat(currentString, &amp;currentCharacter);
          }
      } while (currentCharacter != '.');
  
      mainList = addNode(mainList, currentString);
  
  
      printList(mainList);
  
      return 0;
  }
  </code></pre>