Why am I getting a segmentation fault from calling create_post in make_post?
#include "friends.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

/*
 * Helper function for create_user to handle the creation of users
 * Given name and pointer to next user
*/
User *create_node(const char *name, User *next) {
    User *new_user = malloc(sizeof(User));
    if(new_user == NULL) {
            printf("Error: Memory cannot be allocated");
            exit(1);
    }
    strcpy(new_user->name, name);
    new_user->next = next;

    return new_user;
}

Post *create_post(char *contents) {
    Post *new_post = malloc(sizeof(Post));
    if(new_post == NULL) {
            printf("Error: Memory cannot be allocated");
            exit(1);
    }
    strcpy(new_post->contents, contents);

    return new_post;
}

/*
 * Helper function for create_user to handle insertion of new user into list
 * Given name, pointer to front of the list, and the postition to insert at
*/
void insert_new_user_to_list(const char *name, User *front) {
    User *curr_user = front;
    while (curr_user->next != NULL) {
        curr_user = curr_user->next;
    }
    User *new_user = create_node(name, NULL);
    curr_user->next = new_user;
}

/*
 * Helper function for create_user to handle insertion of new user into list
 * Given name, pointer to front of the list, and the postition to insert at
 * user2 is the user being added
 * user 1 is the user whose friends list we are adding to
*/
void insert_users_to_friends(User *user1, User *user2) {
    // find how many friends are currently in user1's friendlist
    // in order to know where to insert the new user
    int num_items = 0;
    while(user1->friends[num_items] != NULL) {
        num_items++;
    }

    // printf("num_items: %d\n", num_items);
    // if user1 has less than 10 friends
    if (num_items < MAX_FRIENDS) {
        // add user2 at the first empty space in user1's friendlist
        user1->friends[num_items] = user2;
    }
    // printf("user1 friend: %s\n", (user1->friends[0])->name);
}

/*
 * Helper function for create_user to get length of the linked list
*/
int get_list_length(User *front, int count) {
    if(front == NULL) {
        return count;
    }
    return get_list_length(front->next, count + 1);
}

/*
 * Create a new user with the given name.  Insert it at the tail of the list
 * of users whose head is pointed to by *user_ptr_add.
 *
 * Return:
 *   - 0 if successful
 *   - 1 if a user by this name already exists in this list
 *   - 2 if the given name cannot fit in the 'name' array
 *       (don't forget about the null terminator)
 */
int create_user(const char *name, User **user_ptr_add) {
    // return 2 if given name cannot fit in the 'name' array
    // strlen(name)-1 bc strlen doesn't count null terminator
    if(strlen(name) > MAX_NAME) {
        return 2;
    }
    //////////////////////////////////////////////////////////////////
    // check if there are 0 users in the system
    if(*user_ptr_add == NULL) {
        User *first_user = create_node(name, NULL);
        *user_ptr_add = first_user;
        return 0;
    }
    //////////////////////////////////////////////////////////////////
    // traverse list of users whose head is pointed to by *user_ptr_add
    // start from the front
    User *curr_user = *user_ptr_add;
    // checking curr_user->next to see when end of the list is reached
    while(curr_user != NULL) {
        // return 1 if user by this name already exists in this list
        if( strcmp(curr_user->name, name) == 0) {
            return 1;
        }
        curr_user = curr_user->next;
    }
    //////////////////////////////////////////////////////////////////    
    // call function to insert new user into the list
    insert_new_user_to_list(name, *user_ptr_add);
    // return 0 upon success
    return 0;
    //////////////////////////////////////////////////////////////////    
    return -1;
}

/*
 * Return a pointer to the user with this name in
 * the list starting with head. Return NULL if no such user exists.
 *
 * NOTE: You'll likely need to cast a (const User *) to a (User *)
 * to satisfy the prototype without warnings.
 */
User *find_user(const char *name, const User *head) {
    // to traverse list, start from the head
    const User *curr_user = head;
    while(curr_user != NULL) {
        // if a user with matching name is found
        if(strcmp(curr_user->name, name) == 0) {
            // return pointer to the user
            return (User *)curr_user;
        }
        curr_user = curr_user->next;
    }
    return NULL;
}

/*
 * Print the usernames of all users in the list starting at curr.
 * Names should be printed to standard output, one per line.
 */
void list_users(const User *curr) {
    const User *curr_user = curr;
    printf("User List\n");
    while(curr_user != NULL) {
        printf("\t%s\n", curr_user->name);
        curr_user = curr_user->next;
    }
}


/*
 * Change the filename for the profile pic of the given user.
 *
 * Return:
 *   - 0 on success.
 *   - 1 if the file does not exist or cannot be opened.
 *   - 2 if the filename is too long.
 */
int update_pic(User *user, const char *filename) {
    // return 2 if given filename too long
    // strlen(filename)-1 bc strlen doesn't count null terminator
    if(strlen(filename)-1 > MAX_NAME) {
        return 2;
    }
    //////////////////////////////////////////////////////////////////
    FILE *file = fopen(filename, "r");
    // if file exists and can be opened
    if(file != NULL) {
        fclose(file);
        strcpy(user->profile_pic, filename);
        // return 0 on success
        return 0;
    } else {
        // return 1 if file does not exist or cannot be opened
        return 1;
    }
    //////////////////////////////////////////////////////////////////
    return -1;
}


/*
 * Make two users friends with each other.  This is symmetric - a pointer to
 * each user must be stored in the 'friends' array of the other.
 *
 * New friends must be added in the first empty spot in the 'friends' array.
 *
 * Return:
 *   - 0 on success.
 *   - 1 if the two users are already friends.
 *   - 2 if the users are not already friends, but at least one already has
 *     MAX_FRIENDS friends.
 *   - 3 if the same user is passed in twice.
 *   - 4 if at least one user does not exist.
 *
 * Do not modify either user if the result is a failure.
 * NOTE: If multiple errors apply, return the *largest* error code that applies.
 */
int make_friends(const char *name1, const char *name2, User *head) {
    User *user1 = find_user(name1, head);
    User *user2 = find_user(name2, head);

    if(user1 == NULL || user2 == NULL) {
        return 4;
    }
    //////////////////////////////////////////////////////////////////
    // Return 3: check if users are the same
    if(user1 == user2) {
        return 3;
    }
    //////////////////////////////////////////////////////////////////
    // Return 1: check if they are friends already
    // find user1 only since friendship is symmetric
    // search through user1's friendlist for user2
        // to traverse list, start from the head
    User **curr_user = user1->friends;
    while(*curr_user != NULL) {
        // if a user with matching name is found
        if(strcmp((*curr_user)->name, name2) == 0) {
            // return pointer to the user
            return 1;
        }
        *curr_user = (*curr_user)->next;
    }
    //////////////////////////////////////////////////////////////////
    // Return 2: now we know theyre not friends
    // so check if either one has MAX_FRIENDS friends
    // get sizes of both user's friend lists
    int user1_size = sizeof(user1->friends) / sizeof(User);
    int user2_size = sizeof(user2->friends) / sizeof(User);
    // if either one has MAX_FRIENDS return 2
    if (user1_size == MAX_FRIENDS || user2_size == MAX_FRIENDS) {
        return 2;
    }
    //////////////////////////////////////////////////////////////////    
    // if all things are false (didnt return 4,3,2, or 1), we can make them friends
    // insert user2 into user1's friend array
    // insert user1 into user2's friend array
    insert_users_to_friends(user1, user2);
    insert_users_to_friends(user2, user1);
    return 0;
    //////////////////////////////////////////////////////////////////
    return -1;
}


/*
 * Print a user profile.
 * For an example of the required output format, see the example output
 * linked from the handout.
 * Return:
 *   - 0 on success.
 *   - 1 if the user is NULL.
 */
int print_user(const User *user) {
    if(user == NULL) {
        return 1;
    }
    // TODO: print user's pfp
    printf("Name: %s\n", user->name);
    printf("------------------------------------------\n");
    printf("Friends: \n");
    // print friends in user's friend list
    for(int i=0; i < MAX_FRIENDS; i++) {
        if(((user->friends)[i]) != NULL) {
            printf("%s\n", ((user->friends)[i])->name);
        }
    }
    printf("------------------------------------------\n");
    printf("Posts: \n");
    // print all posts in user's array of posts
    Post *curr_post = user->first_post;
    while(curr_post != NULL) {
        printf("From: %s\n", curr_post->author);
        time(curr_post->date);
        printf("Date: %s\n", ctime(curr_post->date));
        printf("\n");
        printf("%s\n", curr_post->contents);
        // print this between posts unless it is the last post
        if(curr_post->next != NULL) {
            printf("\n");
            printf("===\n");
            printf("\n");
        }
        curr_post = curr_post->next;
    }
    printf("------------------------------------------\n");
    
    return 0;
    return -1;
}


/*
 * Make a new post from 'author' to the 'target' user,
 * containing the given contents, IF the users are friends.
 *
 * Insert the new post at the *front* of the user's list of posts.
 *
 * 'contents' is a pointer to heap-allocated memory - you do not need
 * to allocate more memory to store the contents of the post.
 *
 * Return:
 *   - 0 on success
 *   - 1 if users exist but are not friends
 *   - 2 if either User pointer is NULL
 */
int make_post(const User *author, User *target, char *contents) {
    // return 2 if either User pointer is NULL
    if (author == NULL || target == NULL) {
        return 2;
    }
    // checkcing if target is in author's friend list
    User *curr_user = *(author->friends);
    while(curr_user != NULL) {
        // if author and target are friends
        if(strcmp((curr_user)->name, target->name) == 0) {
            // insert new post at front of user's list of posts
            Post *new_post = create_post(contents);
            // put in contents, author, date
            strcpy(new_post->author, author->name);
            time_t date;
            time(&date);
            new_post->date = (&date);
            // make next of new_post the front
            new_post->next = target->first_post;
            // make target->first_post point to the new_post
            target->first_post = new_post;
            // return 0 on success
            return 0;
        } else {
            // users exist but are not friends
            return 1;
        }
        curr_user = curr_user->next;
    }
    return -1;
}


/*
 * From the list pointed to by *user_ptr_del, delete the user
 * with the given name.
 * Remove the deleted user from any lists of friends.
 *
 * Return:
 *   - 0 on success.
 *   - 1 if a user with this name does not exist.
 */
int delete_user(const char *name, User **user_ptr_del) {
    return -1;
}
