title: Deleting a node from a pointer linked list
body: <p>I have a program that adds school courses to a linked list. I'm able to add the courses to the list and print them out.</p>
  
  <p>However I cant delete a course from the linked list (remove_course function). For some reason the CourseList I pass into delete_from_list is equal to NULL.</p>
  
  <p><strong>main.c</strong></p>
  
  <pre><code>#define _CRT_SECURE_NO_WARNINGS
  
  #include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdbool.h&gt;
  #include "bst.h"
  #include "courseList.h"
  
  /* Add course to the given linked list */
  void add_course(CourseList *self)
  {
      char course_name[100];
      Course *c;
  
      printf("enter a course name: \n");
      scanf("%s", course_name);
  
      c = (Course*)malloc(sizeof(struct course));
  
      c-&gt;name = (char*)malloc(strlen(course_name) + 1);
      strcpy(c-&gt;name, &amp;course_name);
      c-&gt;students = NULL;
  
      insert_at_front(self, *c);
  }
  
  /* Remove a given course from the given linked list */
  void remove_course(CourseList *self)
  {
      char course_name[100];
      printf("What course would you like to remove?\n");
      scanf("%s", course_name);
      delete_from_list(self, course_name);
  }
  
  /* Print the courses in the given linked list */
  void print_courses(CourseList *self)
  {
      CourseList current;
      current = *self;
      printf("Your list is: \n");
      while (current != NULL) 
      {   
          printf("%s\n", current-&gt;data.name); 
          current = current-&gt;next; 
      }
      printf("\n");    
  }      
  
  int main(void)
  {       
      CourseList master;    
      int choice;
  
      printf("Welcome to student enrolment\n");
  
      while (true)
      { 
          printf("Pick your option\n");
          scanf("%d", &amp;choice);
          switch (choice)
          {
          case 0:
              exit(1);
              break;
          case 1:
              add_course(&amp;master);
              printf("%s was add to the list!\n", master-&gt;data.name);
              break;
          case 2:
              print_courses(&amp;master);
              break;
          case 3:
              remove_course(&amp;master);
              break;
          }    
      }    
  }
  </code></pre>
  
  <p><strong>CourseList.c</strong></p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdbool.h&gt;
  #include "bst.h"
  #include "courseList.h"
  
  
  void insert_at_front(CourseList *cl, Course c)
  {
      CourseList newNode;
  
      newNode = (CourseList)malloc(sizeof(struct courseNode));
      newNode-&gt;data = c;
      newNode-&gt;next = *cl;
  
      *cl = newNode;    
  }    
  
  void delete_from_list(CourseList *self, char *course_name)
  {
      CourseList current = *self;
      CourseList prev = NULL;
      CourseList to_free = NULL;
  
      while (current != NULL)
      {
          if (strcmp(current-&gt;data.name, course_name) == 0) //Error here current has nothing in it
          {
              if (prev == NULL)
              {
                  *self = current-&gt;next;
                  free(current);
                  current = *self;
              }
              else
              {
                  prev-&gt;next = current-&gt;next;
                  free(current);
                  current = prev-&gt;next;
              }
          }
          else
          {
              prev = current;
              current = current-&gt;next;
          }
      }
  }
  </code></pre>
  
  <p><strong>CourseList.h</strong></p>
  
  <pre><code>#include "bst.h"
  
  #ifndef COURSELIST_H
  #define COURSELIST_H
  
  struct course;
  typedef struct course Course;
  
  struct courseNode;
  typedef struct courseNode *CourseList;
  
  typedef struct course
  {
      char *name;
      BST students;
  
  } Course;
  
  typedef struct courseNode
  {
      Course data;
      struct courseNode *next;
  
  } *CourseList;
  
  void insert_at_front(CourseList *cl, Course c);
  void delete_from_list(CourseList *self, char *course_name);
  
  #endif
  </code></pre>
  
  <p><strong>bst.h</strong></p>
  
  <pre><code>#ifndef BST_H
  #define BST_H
  
  typedef struct bstNode
  {
      long student_id;
      struct bstNode*left;
      struct bstNode*right;
  
  } *BST;
  
  #endif
  </code></pre>