I am trying to copy a struct's contents into another struct of the same type.
I would like to be able to change the values of one struct without it affecting the other later though.
I am dealing with reading and editing PPM files. I have a struct:
typedef struct {
char format[4];
char comments[MAX_COMMENT_LENGTH];
int width, height, maxColourValue;
PPMPixel **pixels;
} PPMImage;
And then I have a copy function to copy the values over but I get an error when assigning different fields.
I am trying to copy the fields of newPPM into messagePPM.
Error:
incompatible types when assigning to type 'char[4]' from type 'char *'
messagePPM->format = newPPM->format;
incompatible types when assigning to type 'char[100]' from type 'char *'
messagePPM->comments = newPPM->comments;
Copy Function:
//A function to copy contents of one PPMImage to another
void copyPPM(PPMImage *newPPM, PPMImage *messagePPM) {
messagePPM->format = newPPM->format;
messagePPM->comments = newPPM->comments;
messagePPM->width = newPPM->width;
messagePPM->height = newPPM->height;
messagePPM->maxColourValue = newPPM->maxColourValue;
messagePPM->pixels = newPPM->pixels;
}
How do I fix my error? Will copying fields this way achieve what I am aiming for?