#include "friends.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

const int MAX_PFP = 40;
/*
 * 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) {
    User *new = malloc(sizeof(User));
    User *curr = *user_ptr_add;
    User *prev = NULL;
    if (new < 0){
        return -1;
    }

    if(strlen(name) >= MAX_NAME){
        return 2;
    }

    printf("%s\n", name);
    while(curr != NULL){
        if(strcmp(curr->name, name) == 0){
            return 1;
        }
        prev = curr;
        curr = curr->next;
    }

    strncpy(new->name, name, MAX_NAME);
    printf("%s\n", new->name);
    prev->next = new;   
    return 0;
}
 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.