How should I implement my device write function?

I'm having trouble with part of a game project. For the project we're supposed to create a device driver for a dice that we implement later in the project. My problem is that my dice_write() function doesn't seem to be working, or even being reached at all. I'm wondering if it's due to the driver code, or the way I'm implementing it within the project.

Here is the relevant part of the driver .c file:

static int SIDES = 6;

unsigned char get_random_byte(int max)
    unsigned char c;
    get_random_bytes(&c, 1);
    return ((c%max)+1);

//dice_read omitted (it works fine)

static ssize_t dice_write(struct file * file, const char * buf, size_t count, loff_t *ppos)
    printk(KERN_ERR "WRITE");
    int j;
    int len = sizeof(int);
    if(*ppos != 0)
        return 0;
    if(copy_from_user(buf, j, 1))
        return -EINVAL;
    *ppos = len;
    SIDES = j;
    printk(KERN_ERR "\nSides: %d",SIDES);
    //printk(KERN_ERR "write(file, 0x%p, %d, %lld)\n", buf, count, *ppos);
    return len;

And here is how I implemented it within the project:

int roll(int sides)
    unsigned int roll;
    int i = open("/dev/dice", O_RDWR);
    write(i, &sides, sizeof(int));
    read(i, &roll, sizeof(int));
    printf("ROLL: %d\n",roll);
    return roll;

Currently read works, but write doesn't so SIDES is never updated and there is no output from the printks, which is what I want (the program is a game where the sides of the dice differ so I need to write a new number to sides). Can anyone help me figure out how to implement write correctly?