/* Read from the open file fp, and create the linked data structure
    9    that represents the Makefile contained in the file.
   10    See the top of pmake.h for the specification of Makefile contents.
   11  */
   12 Rule *parse_file(FILE *fp) {
   13     // Implement this function and remove the stubbed return statement below.
   14
   15     // Initialize the head node
   16     Rule *head = malloc(sizeof(Rule));
   17
   18     // Initialize the variable to store the output from each line of the file
   19     char output[MAXLINE];
   20
   21     // Create a variable to iterate over
   22     Rule *curr = head;
   23
   24     // Traverse the file
   25     while (fgets(output, MAXLINE, fp) != NULL) {
   26
   27         // Check if it's a target
   28         if (output[0] != '\t' && is_comment_or_empty(output) == 0) {
   29             // printf("%s", output);
   30             // Find the target from the current line
   31             char *ptr = strchr(output, ':');
   32
   33             // Copy the length of ptr - 1 to the target variable
   34             int size = strlen(ptr) - 1;
   35             curr->target = malloc(sizeof(char) * size);
   36             strncpy(curr->target, ptr, size - 1);
   37             curr->target[size] = '\0';
   38
  39             // TODO: Properly initialize rest of struct
   40             curr->dependencies = NULL;
   41             curr->actions = NULL;
   42             curr->next_rule = malloc(sizeof(Rule));
   43             curr = curr->next_rule;
   44
   45         // Otherwise it's an action line
   46         } else if (output[0] == '\t' && is_comment_or_empty(output) == 0) {
   47             // If its an action, parse the args into
   48             // a heap allocated list
  49             // TODO: Delete:
   50             // printf("%s", output);
   51         }
   52     }
   53
   54     return head;
   55 }
Currently, this code always produces a segmentation fault