title: Nullptr error during adding structures to list
body: <p>I've written my own list in C, but during adding 2nd object to it I've `Exception thrown: write access violation. It occures in addToList() function (I've commented the line). Can you tell me why i'm getting an error. I've initialized head in main method:</p>
  
  <pre><code>void main()
  {
      struct List *head = malloc(sizeof(head));
      head-&gt;next = NULL;
      head-&gt;person = NULL;
      //head = NULL;
      addToList(head,"Abdul","Marin","21312321321");
      addToList(head, "Karmowski", "Byk", "24214541");
      displayList(head);
      getchar();
      return 0;
  
  }
  </code></pre>
  
  <p><strong>List.h file:</strong></p>
  
  <pre><code> struct List
      {
          struct Person *person;
          struct List *next;
      };
  </code></pre>
  
  <p><strong>List.c file:</strong></p>
  
  <pre><code>void addToList(struct List * head, char *name, char *surname, char *id)
  {
      struct List *tmp = head;
      struct Osoba *newPerson= malloc(sizeof *newPerson);
      newPerson-&gt;name = name;
      newPerson-&gt;surname = surname;
      newPerson-&gt;id = id;
      if (tmp-&gt;person==NULL)
      {
          head-&gt;person = newPerson;
      }
      else if (tmp-&gt;next==NULL)
      {
          head-&gt;next-&gt;person = newPerson; // HERE OCCURES ERROR
      }
      else
      {
          while (tmp-&gt;next!=NULL)
          {
              tmp = tmp-&gt;next;
          }
          tmp-&gt;next-&gt;person = newPerson;
      }
  
  }
  </code></pre>