I've been struggling to create a new node, that has a pointer to a node of different type in it, and a pointer to the next node. Below are my two structs:
// Frame struct
typedef struct Frame
{
char* name;
unsigned int duration;
char* path;
} Frame;
// Link (node) struct
typedef struct FrameNode
{
Frame* frame;
struct FrameNode* next;
} FrameNode;
And my attempt to create a new node of type FrameNode:
/**
This function creates a new frame.
input: name - the name of the frame we want to create, duration - the duration of the frame we want to create, path - the path of the frame we want to create
output: newFrame - a new frame, that will be added to the end of the list of frames
*/
FrameNode* createFrame(char* name, unsigned int duration, char* path) {
FrameNode* newFrame = (FrameNode*)malloc(sizeof(FrameNode));
newFrame->frame = (Frame*)malloc(sizeof(Frame)); // create memory for the Frame* inside of FrameNode*
strcpy(newFrame->frame->name, name);
newFrame->frame->duration = duration;
strcpy(newFrame->frame->path, path);
return (newFrame);
}
I think the problem is related somehow to strcpy, but I'm not entirely sure. I've used it in the past with no issues at all, so that's strange. Thanks :)