DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C (http://www.daniweb.com/forums/forum118.html)
-   -   What's the difference?(linked list) (http://www.daniweb.com/forums/thread113941.html)

Syntax Error Mar 14th, 2008 1:33 pm
What's the difference?(linked list)
 
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!!

Ancient Dragon Mar 14th, 2008 6:23 pm
Re: What's the difference?(linked list)
 
>>//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.


All times are GMT -4. The time now is 9:29 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC