when delete user, which associated heap memory is not freed
int create_user(const char *name, User **user_ptr_add) {
    if (strlen(name) > MAX_NAME - 1){
        return 2;
    }

    User *new_usr = malloc(sizeof(User));
    if (new_usr == NULL){perror("malloc");exit(1);}
    strcpy(new_usr->name, name);
    
    if (user_ptr_add == NULL){
        user_ptr_add = malloc(sizeof(User *));
        if (user_ptr_add == NULL){perror("malloc");exit(1);}
        *user_ptr_add = new_usr;
    } else {
        if (*user_ptr_add != NULL){
            User *curr_usr = *user_ptr_add;
            while (curr_usr != NULL && curr_usr->next != NULL){
                if (strcmp(curr_usr->name, name) == 0){
                    return 1;
                }
                curr_usr = curr_usr->next;
            }
            if (strcmp(curr_usr->name, name) == 0){
                return 1;
            }
            curr_usr->next = new_usr;
        } else {
            *user_ptr_add = new_usr;
        }
    }
    return 0;
}

User *find_user(const char *name, const User *head) {
    User *curr_usr = (User *)head;
    while (curr_usr != NULL){
        if (strcmp(curr_usr->name, name) == 0){
            return curr_usr;
        }
        curr_usr = curr_usr->next;
    }
    return NULL;
}

void list_users(const User *curr){
    printf("User List\n");
    User *curr_usr = (User *)curr;
    while (curr_usr != NULL){
        printf("  %s\n", curr_usr->name);
        curr_usr = curr_usr->next;
    }
}

int update_pic(User *user, const char *filename) {
    FILE *pic_file;
    pic_file = fopen(filename, "r");
    if (pic_file == NULL){
        return 1;
    }
    
    if (strlen(filename) > MAX_NAME - 1){
        return 2;
    }

    strncpy(user->profile_pic, filename, MAX_NAME);
    return 0;
}

int make_friends(const char *name1, const char *name2, User *head) {
    int error = 0;
    // name1 == name2: return 3
    if (strcmp(name1, name2) == 0){
        error = 3;
    }

    // either name not exist: return 4
    User *usr1 = head, *usr2 = head;
    while (usr1 != NULL && strcmp(usr1->name, name1) != 0){
        usr1 = usr1->next;
    }
    while (usr2 != NULL && strcmp(usr2->name, name2) != 0){
        usr2 = usr2->next;
    }

    if (usr1 == NULL || usr2 == NULL){
        return 4;
    }
    
    if (error == 0){
        // friends full: return 2; already friends: return 1
        int i = 0;
        while (i < MAX_FRIENDS &&  (usr1->friends)[i] != NULL){
            if (strcmp(((usr1->friends)[i])->name, name2) == 0){
                if (error < 1){error = 1;}
                }
                i++;
            }
            if (i == MAX_FRIENDS){
                if (error < 2){
                    error = 2;
            }
        }
        

        int j = 0;
        while (j < MAX_FRIENDS &&  (usr2->friends)[j] != NULL){
            if (strcmp(((usr2->friends)[j])->name, name1) == 0){
                if (error < 1){
                    error = 1;
                }
            }
            j++;
        }
        if (j == MAX_FRIENDS){
            if (error < 2){
                error = 2;
            }
        }

        //make friends
        if (error == 0){
            (usr2->friends)[j] = usr1;
            (usr1->friends)[i] = usr2;
        }
    }
    return error;
}

int print_user(const User *user) {
    if (user == NULL){
        return 1;
    }
    //pic
    FILE *pic = fopen(user->profile_pic, "r");
    if (pic != NULL){
        char c = fgetc(pic);
        while (c != EOF){
            printf("%c", c);
            c = fgetc(pic);
        }
        fclose(pic);
        printf("\n");
    }

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

    //friends
    printf("Friends:\n");
    if ((user->friends != NULL) && (*(user->friends) != NULL)){
        int i = 0;
        while (i < MAX_FRIENDS && (user->friends)[i] != NULL){
            printf("%s\n", ((user->friends)[i])->name);
            i++;
        }
    }
    printf("------------------------------------------\n");

    //post
    printf("Posts:\n");
    Post *pst = user->first_post;
    if (user->first_post != NULL && pst != NULL){
        char *curr_time_str = ctime(pst->date);
        printf("From: %s\n", pst->author);
        printf("Date: %s\n", curr_time_str);
        printf("\n");
        printf("%s\n", pst->contents);
        pst = pst->next;
    }
    while (pst != NULL){
        if (pst->next != NULL){
            printf("\n===\n\n");
            printf("From: %s\n", pst->author);
            char *curr_time_str = ctime(pst->date);
            printf("Date: %s\n", curr_time_str);
            printf("\n");
            printf("%s\n", pst->contents);
            printf("\n");
            pst = pst->next;
        } else {
            printf("\n===\n\n");
            printf("From: %s\n", pst->author);
            char *curr_time_str = ctime(pst->date);
            printf("Date: %s\n", curr_time_str);
            printf("\n");
            printf("%s\n", pst->contents);
            pst = pst->next;
        }
        
    }
    printf("------------------------------------------\n");
    return 0;
}

int make_post(const User *author, User *target, char *contents) {
    if (author == NULL || target == NULL){
        return 2;
    }
    if (author-> friends == NULL){
        return 1;
    }
    int i = 0;
    User *curr_usr = author->friends[0];
    while (curr_usr != NULL && strcmp(curr_usr->name, target->name) != 0){
        i++;
        curr_usr = author->friends[i];
    }
    if (curr_usr == NULL){
        return 1;
    }

    Post *new_post = malloc(sizeof(Post));
    if (new_post == NULL){perror("malloc");exit(1);}
    strcpy(new_post->author, author->name);
    new_post->contents = contents;
    time_t *curr_time = malloc(sizeof(time_t));
    if (curr_time == NULL){perror("malloc");exit(1);}
    time(curr_time);
    new_post->date = curr_time;

    new_post->next = curr_usr->first_post;
    curr_usr->first_post = new_post;

    return 0;
}

int delete_user(const char *name, User **user_ptr_del) {
    if (*user_ptr_del == NULL){
        return 1;
    }

    //delete from user_ptr_del
    User *curr_usr = *user_ptr_del;
    User *prev_usr = curr_usr;
    while (curr_usr != NULL){
        if (strcmp(curr_usr->name, name) == 0){
            break;
        }
        prev_usr = curr_usr;
        curr_usr = curr_usr->next;
    }
    if (curr_usr == NULL){
        return 1;
    }
    if (curr_usr != NULL && *user_ptr_del == curr_usr){
        prev_usr = NULL;
        *user_ptr_del = curr_usr->next;
    } else {
        prev_usr->next = curr_usr->next;
    }

    //delete from friend
    User *friend = *user_ptr_del;
    while (friend != NULL){
        int i = 0;
        while ((friend->friends)[i] != NULL){
            if (strcmp((friend->friends)[i]->name, name) == 0){
                break;
            }
            i++;
        }
        if ((friend->friends)[i] == NULL){
            friend = friend->next;
            continue;
        } else {
            friend->friends[i] = NULL;
            for (; i < MAX_FRIENDS - 1 && (friend->friends)[i] != NULL; i++){
                (friend->friends)[i] = (friend->friends)[i + 1];
            }
            if (i == MAX_FRIENDS - 1){
                (friend->friends)[i] = NULL;
            }
        }
        friend = friend->next;
    }

    //free
    Post *curr_post = curr_usr->first_post;
    while (curr_post != NULL){
        Post *next_post = curr_post->next;
        free(curr_post->date);
        free(curr_post);
        curr_post = next_post;
    }
    free(curr_usr);

    if (*user_ptr_del == NULL){
        free(user_ptr_del);
    }

    return 0;
}