Hi,
I have a code which takes some arrays and pointers for a linked list but returns every time NULL for head. I couldn't find a solution for it.
Can you help me about this?
Thanks.
(I added my function)
Code:
int read_score(struct all_answers *curr, struct all_answers *head_t, struct all_answers *tail, int pick[], int guess[]){
pm_unit pm_unit_0;
pm_unit_0 = score(pick, guess);
count++;
printf("%d %d %d %d %d %d => +%d -%d\n", count, guess[0], guess[1], guess[2], guess[3], guess[4], pm_unit_0.plus, pm_unit_0.minus);
answer[5] = pm_unit_0.plus; answer[6] = pm_unit_0.minus;
answer[0] = guess[0]; answer[1] = guess[1]; answer[2] = guess[2]; answer[3] = guess[3]; answer[4] = guess[4];
curr = (struct all_answers *)malloc(sizeof(struct all_answers));
curr->answer_list[6] = answer[6];
curr->answer_list[5] = answer[5];
curr->answer_list[4] = answer[4];
curr->answer_list[3] = answer[3];
curr->answer_list[2] = answer[2];
curr->answer_list[1] = answer[1];
curr->answer_list[0] = answer[0];
printf("curr->answer_list[4]: %d\n", curr->answer_list[4]);
if(head_t == NULL){
printf("NULL returned inside read_score for head\n");
head_t = curr;
curr->prev = NULL;
if(head_t == NULL)
printf("head returned NULL after assignment\n");
}
else{
tail->next = curr;
curr->prev = tail;
}
tail = curr;
curr->next = NULL;
printf("tail->answer_list[4]: %d\n", tail->answer_list[4]);
return pm_unit_0.plus;
}