0

hi there.....i wonder what's the difference with these 2 linked list...

1.
struct node
{
	int wage;
	int hours_worked;
	int salary;
	int hoursW; 
	char* name;
	struct node *link;
};
2.
struct listNode 
{			
   char data;	
   struct listNode *nextPtr; 
}; 
typedef struct listNode ListNode; /* synonym for struct listNode */
typedef ListNode *ListNodePtr; /* synonym for ListNode* */

and this....

temp->name=(char*)malloc(strlen(tempString)+1);
//this is based on the linked list example 1(above)
//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!!

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by Ancient Dragon
0

>>//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.

char str[255] = "Hello";

in the above, sizeof(str) is 255, but strlen(str) is only 5.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.