You forgot the pointer in the function prototype:
int listsize(listrec*);
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
>int sum = listsize(*temp);
Try removing the *. And what in the world is "temp" doing in your program? You haven't even assigned it to anything when you pass it as an argument to listsize() !
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
*groan*
Your code was almost there, but now you wrecked it...
>Write a function called listsize that takes a pointer to start of linked list
OK, think about this. Where is the start of the linked list? Is it some random variable that you just declared, or do you think it's one of the pointers you assigned previously? Think about this carefully.
Your previous attempt was almost there except that you were passing the wrong thing to the function. That's it. This latest "revision" has made things far worse.
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
It's time you start using code tags. This is getting really annoying and hard to read your code.
A few problems:
int listsize(listrec * head)
{
int num=0;
listrec *p = head;
while(*p!=NULL) // remove the *
{
*p = *p -> next; // remove the *s.
num++;
};
return num;
}
You see, by using a *, you dereference the pointer, and in fact in the while loop you're checking that the actual memory inside the struct is not null, which is wrong. You want to check for a nullpointer, so then don't use a *. Same goes for the other line.
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339