Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I do not know what this means. I have a linked list functionthat I am trying to

ID: 3626463 • Letter: I

Question

I do not know what this means. I have a linked list functionthat I am trying to complete, but I keep getting this same error on 3 lines. Please help me to understand what this warning means and how to get rid of it. Clearly!


struct KMS *sale(struct KMS *list, FILE *fp)
{

int i;
struct KMS *pNew = NULL;
struct KMS *help_ptr = NULL;

pNew -> itemsPurchased = malloc(sizeof(pNew -> numItemsOnList));

pNew = (struct KMS*)malloc(sizeof(struct KMS));
fscanf(fp, "%s", pNew -> firstName);
fscanf(fp, "%s", pNew -> lastName);
fscanf(fp, "%d", &pNew -> numItemsOnList);
for(i = 0; i < pNew -> numItemsOnList; i++)
{
fscanf(fp, "%d", &pNew -> itemsPurchased[i]);
}
help_ptr = list;

if(list == NULL)
pNew -> next = list; //warning here

while(help_ptr -> next != NULL)
help_ptr = help_ptr -> next; // go to very last node //warning here
pNew -> next = help_ptr -> next; // new node points to last; NULL
help_ptr -> next = pNew; //make help_ptr point to the new node //warning here
return list;
}

Explanation / Answer

Can't say definitely without seeing your struct KMS declaration, but this is my hypothesis: pNew is a struct KMS pointer as is list, but *next in your struct KMS declaration might be a KMS pointer and NOT a struct KMS pointer. This is similar to what I think your issue is: http://stackoverflow.com/questions/2683957/assignment-from-incompatible-pointer-type "assignment from incompatible pointer type" means you're trying to assign a pointer to a datatype which it's not supposed to point to. Assigning a struct KMS pointer to a KMS pointer would be this type of issue.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote