What's the difference?(linked list)

Reply

Join Date: Mar 2008
Posts: 4
Reputation: Syntax Error is an unknown quantity at this point 
Solved Threads: 0
Syntax Error Syntax Error is offline Offline
Newbie Poster

What's the difference?(linked list)

 
0
  #1
Mar 14th, 2008
hi there.....i wonder what's the difference with these 2 linked list...
  1. 1.
  2. struct node
  3. {
  4. int wage;
  5. int hours_worked;
  6. int salary;
  7. int hoursW;
  8. char* name;
  9. struct node *link;
  10. };

  1. 2.
  2. struct listNode
  3. {
  4. char data;
  5. struct listNode *nextPtr;
  6. };
  7. typedef struct listNode ListNode; /* synonym for struct listNode */
  8. typedef ListNode *ListNodePtr; /* synonym for ListNode* */

and this....
  1. temp->name=(char*)malloc(strlen(tempString)+1);
  2. //this is based on the linked list example 1(above)
  3. //why this doesnt have sizeof? =)

i hope someone will answer me.........pls explain in simple english so that i can understand well...im not an American...=) thank a lot..peace!!
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,358
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1463
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: What's the difference?(linked list)

 
0
  #2
Mar 14th, 2008
>>//why this doesnt have sizeof? =)temp->name=(char*)malloc(strlen(tempString)+1);
>>//this is based on the linked list example 1(above)
>>//why this doesnt have sizeof? =)

It doesn't use sizeof(tempString) probably sizeof(any pointer here) is only 4 on 32-bit machines while the length of the string can be much much more than that. And the size of a character array may or may not be the same as the length of the string in the array.
  1. char str[255] = "Hello";
in the above, sizeof(str) is 255, but strlen(str) is only 5.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC