/*
 * 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) {
        // Open profile picture
        FILE *file = fopen(user->profile_pic, "r");
        char char_part;
        while (file != NULL && (char_part = fgetc(file)) != EOF) {
            printf("%c", char_part);
        }
        if (file != NULL) {
            printf("\n");
        }
        fclose(file);
    
        // Print out name
        printf("%s %s\n", "Name:", user->name);
        printf("%s\n", "------------------------------------------");

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

        // Make post section
        printf("%s\n", "Posts:");
        Post *curr = user->first_post; 
        while (curr != NULL){
            printf("%s %s\n", "From:", curr->author);
            printf("%s %s\n", "Date:", ctime(curr->date));
            printf("\n");
            printf("%s\n", curr->contents);
            if (curr->next != NULL) { // Checks if there is another post
                printf("\n");
                printf("%s\n", "===");
                printf("\n");
            }
            curr = curr->next;
        }
        printf("%s\n", "------------------------------------------");
        return 0;
    }
    else {
        // User is NULL
        return 1;
    }

}
How to get rid to segmentation fault?