I have a pointer to a Tasks struct which has three fields, tid,difficulty & next. I want to compare the difficulty of the next task from a task with a number but i'm getting the attached error when i try what you're seeing below:
struct Tasks
{
int tid; /*Task's identifier*/
int difficulty; /*Task's difficulty*/
struct Tasks *next; /*Pointer to the next node*/
};
struct Tasks* curr = (*player)->tasks_head->next;
if(curr->next->difficulty < difficulty) {...}
Here's how i'm allowcating memory for a new node:
struct Tasks* node = (struct Tasks*) malloc(sizeof(struct Tasks)); // could return null if not enough mem
if(node == NULL) return 0;
// add data to the new node
node->tid = tid;
node->difficulty = difficulty;
node->next = NULL;
Exception thrown: read access violation. curr->next was 0xCDCDCDCD
I thought i can dereference the next pointer by doing *(curr->next)->difficulty
but that doesn't allow me to compile and i don't understand why.