Error in debug: Read access violation current was 0xCDCDCDCD
Please help me
This is the struct
typedef struct node
{
int data;
struct node* next;
} node_t;
This is the function for add new data
node_t* push(node_t* head, int data)
{
node_t* current = (node_t*)malloc(sizeof(node_t));
current->data = data;
current->next = head;
head = current;
return current;
}
This function print all data of the list
void print_list(node_t* head)
{
node_t* current = head;
while (current != NULL)
{
printf("Data: %d\n", current->data); // READ ACCESS VIOLATION
current = current->next;
}
}
Main of program
int main()
{
node_t* head = (node_t*)malloc(sizeof(node_t));
head = push(head, 1);
head = push(head, 2);
print_list(head);
return 0;
}