I want to allocate memory to structures in function and assign the values given as parameters to the function. My code:
linkedList.c
FrameNode* createFrameNode(char name[MAX_NAME], int duration, char path[MAX_PATH])
{
Frame* newFrame = malloc(sizeof(Frame));
FrameNode* newNode = malloc(sizeof(FrameNode));
// Copy name
strcpy(newFrame->name, name);
// Add duration and path
newFrame->duration = duration;
strcpy(newFrame->path, path);
// Attach new frame to the new node
newNode->frame = newFrame;
newNode->next = NULL;
return newNode;
}
I get an error back:
Exception thrown at 0x00007FFF18C4D215 (ucrtbased.dll) in C_Project.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
If I try to get any memory related to the structs. Can you tell what is wrong from my code?
The structs in linkedList.h
// 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;