'use memcpy to fill a struct taking data from an array in C

The following task is from an exam I took in engineering school (mechanical engineering):

You get an array unsigned char buffer[128]; used to read data from a source byte by byte, containing data of the structure:

struct Pixel {

unsigned char x;
unsigned char y;
unsigned char greyValue;

};

The task is: Create an instance of a pixel and copy the data content from the header of the buffer using "memcpy".

My aproach does not seem to work:

#include <stdio.h>
#include <string.h>

struct Pixel {
    unsigned char x;
    unsigned char y;
    unsigned char greyValue;
};

int main() 
{
    unsigned char buffer[128] = {2,4,44};

    struct Pixel singlePixel;

    memcpy(singlePixel, buffer, 3);

    printf("singlePixel.x = %d\n", singlePixel.x);
    printf("singlePixel.y = %d\n", singlePixel.y);
    printf("singlePixel.greyValue = %d\n", singlePixel.greyValue);


    return 0;
}

I would expect that singlePixel.x = 2, singlePixel.y = 4 and singlePixel.greyValue = 44.

When debugging I get the error: incompatible type for argument 1 of ‘memcpy’

I'm also not at all sure if my approach is up to the task, since I don't understand exactly how this should works with the buffer...



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source