Why may new_post be uninitialized
#include "friends.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

/*
 * 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) {
    if (strlen(name) >= MAX_NAME) {
        return 2;
    }

    User *curr = *user_ptr_add;
    while (curr != NULL) {
        if (strcmp(curr->name, name)) {
            return 1;
        }
        curr = curr->next;
    }

    User new_user;
    strncpy(new_user.name, name, MAX_NAME);
    new_user.name[MAX_NAME-1] = '\0';
    new_user.next = NULL;
    new_user.first_post = NULL;

    for (int i = 0 ; i < MAX_FRIENDS ; i++) {
        new_user.friends[i] = NULL;
    }

    *curr = new_user;

    return 0;
}


/*
 * 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) {
    User *curr = (User *) head;

    while (curr != NULL) {
        if (strcmp(curr->name, name)) {
            return curr;
        }

        curr = curr->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) {
    printf("User List");
    while (curr != NULL) {
        printf("\t%s\n", curr->name);
        curr = curr->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) {
    char filename_str[MAX_NAME];
    strncpy(filename_str, filename, MAX_NAME);
    filename_str[MAX_NAME-1] = '\0';
    if (strcmp(filename, filename_str) != 1) {
        return 2;
    }

    FILE *profile_pic_file = fopen(filename, "r");
    if (profile_pic_file == NULL) {
        return 1;
    }

    fclose(profile_pic_file);

    strncpy(user->profile_pic, filename, MAX_NAME);
    filename_str[MAX_NAME-1] = '\0';

    return 0;
}


/*
 * 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;
    } else if (user1 == user2) {
        return 3;
    }

    User *curr1 = user1->friends[0];
    User *curr2 = user2->friends[0];
    int user1_friends = 0;
    int user2_friends = 0;
    int i = 0;
    int alr_friends = 0;

    while (i < MAX_FRIENDS) {
        if (curr1 == user2 || curr2 == user1) {
            alr_friends = 1;
        }
        if (curr1 != NULL) {
            user1_friends++;
            curr1 = curr1->next;
        }
        if (curr2 != NULL) {
            user2_friends++;
            curr2 = curr2->next;
        }

        i++;
    }

    if ((user1_friends == MAX_FRIENDS || user2_friends == MAX_FRIENDS) && alr_friends == 0) {
        return 2;
    } else if (alr_friends != 0) {
        return 1;
    }

    return 0;

}


/*
 * 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;
    }

    FILE *profile_pic = fopen(user->profile_pic, "r");

    char line[30];

    if (profile_pic != NULL) {
        while (fgets(line, 30, profile_pic) != NULL) {
            line[29] = '\0';
            printf("%s\n", line);
        }
    }
    fclose(profile_pic);

    printf("Name: %s\n", user->name);
    printf("------------------------------------------\n");
    printf("Friends:\n");

    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");

    Post *curr = user->first_post;
    while (curr != NULL) {
        printf("From: %s\n", curr->author);
        printf("Date: %s\n", ctime(curr->date));
        printf("\n");
        printf("%s\n", curr->contents);
        if (curr->next == NULL) {
            printf("------------------------------------------\n");
        } else {
            printf("\n");
            printf("===\n");
            printf("\n");
        }

        curr = curr->next;
    }

    return 0;
}


/*
 * 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) {
    if (target == NULL || author == NULL) {
        return 2;
    }

    int friends = 0;

    for (int i = 0 ; i < MAX_FRIENDS ; i++) {
        if (author->friends[i] == NULL) {
            break;
        } else if (author->friends[i] == target) {
            friends = 1;
        }
    }

    if (!friends) {
        return 1;
    }

    Post new_post;
    strncpy(new_post.author, author->name, MAX_NAME);
    new_post.author[MAX_NAME-1] = '\0';

    strcpy(new_post.contents, contents);
    time(new_post.date);

    new_post.next = target->first_post;

    target->first_post = &new_post;

    return 0;
}


/*
 * 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) {
//    User *curr = *user_ptr_del;
//    while (curr != NULL) {
//        for (int i = 0 ; i < MAX_FRIENDS ; i++) {
//            if (curr->friends[i] == NULL) {
//                break;
//            } else if (curr->friends[i]->name == name) {
//                for (int j = i ; j < MAX_FRIENDS ; j++) {
//                    if (j == MAX_FRIENDS - 1) {
//                        curr->friends[j] = NULL;
//                    } else {
//                        curr->friends[j] = curr->friends[j+1];
//                    }
//                }
//            }
//        }
//        curr = curr->next;
//    }

    User *prev = NULL;
    User *curr = *user_ptr_del;
    int found_user = 0;
    User *del_user;

    while (curr != NULL) {
        if (curr->name == name) {
            del_user = curr;
            found_user = 1;
        }
        if (found_user) {
            del_user = curr;
            prev->next = curr->next;
        }
        prev = curr;
        curr = curr->next;
    }

    for (int i = 0 ; i < MAX_FRIENDS ; i++) {
        if (del_user->friends[i] == NULL) {
            break;
        } else {
            User *friend = del_user->friends[i];
            int shift = 0;
            for (int j = 0 ; j < MAX_FRIENDS ; j++) {
                if (friend->friends[j] == del_user) {
                    shift = 1;
                }
                if (shift) {
                    if (j == MAX_FRIENDS - 1) {
                        friend->friends[j] = NULL;
                    } else {
                        friend->friends[j] = friend->friends[j+1];
                    }
                }
            }
        }
    }

    return 0;
}
