Malloc question

This is a discussion on Malloc question within the C Programming forums, part of the General Programming Boards category; ypedef struct lnode { int data; struct lnode *next; } listnode_t; ok my question about this struct is what is ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    3

    Malloc question

    ypedef struct lnode {
    int data;
    struct lnode *next;
    } listnode_t;


    ok my question about this struct is what is the point of the "listnode_t;" at the end of the struct

    And for the second part of my question

    if given this program

    void initInode(Inode* const IN);

    and told to make it so it makes the first datapoint and the first pointer point to null how would I do it.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    The point of a typedef is to give a new name to a type. So the type that used to be called struct lnode is now called listnode_t.

    Normally to change the values of a variable you use =, with the variable on the left and the value you want to change it to on the right. To access the elements of a struct, you use name_of_struct.name_of_member, like IN.data.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    assuming "typdef" is just missing the 't', listnode_t is a synonym of struct lnode. Both can be used interchangably (but it may confuse the reader if you actually DO use both in the same program).

    What do YOU think should be in initNode - by answering that, you will show what you know and what you don't know, and then we can help you gain further understanding - it would make no sense to explain what you already know, and we may well do that if you don't help us understand where you are at on the learning-curve.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Registered User
    Join Date
    Mar 2009
    Posts
    3
    Quote Originally Posted by matsp View Post
    assuming "typdef" is just missing the 't', listnode_t is a synonym of struct lnode. Both can be used interchangably (but it may confuse the reader if you actually DO use both in the same program).

    What do YOU think should be in initNode - by answering that, you will show what you know and what you don't know, and then we can help you gain further understanding - it would make no sense to explain what you already know, and we may well do that if you don't help us understand where you are at on the learning-curve.

    --
    Mats
    LS->mTop = NULL;

    I thought this would be the only line you needed but it keeps telling me left operand has incompadible type int.

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by jaland10 View Post
    LS->mTop = NULL;

    I thought this would be the only line you needed but it keeps telling me left operand has incompadible type int.
    What is LS and mTop - they do not occur in your original post, so I have no idea what they are, or if they are integer or something else.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Registered User
    Join Date
    Mar 2009
    Posts
    3
    Quote Originally Posted by matsp View Post
    What is LS and mTop - they do not occur in your original post, so I have no idea what they are, or if they are integer or something else.

    --
    Mats
    Really sorry i was looking at the wrong post when i typed that, I ment to say this


    IN -> data =0 ;
    IN->next = NULL;

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    And Inode is defined how?
    Note that Inode is different from Lnode, but it's a typedef (or you are using a C++ compiler).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. malloc + segmentation fault
    By ch4 in forum C Programming
    Replies: 5
    Last Post: 04-07-2009, 03:46 PM
  2. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 12:14 PM
  3. Alternative to malloc
    By stellastarr in forum C Programming
    Replies: 13
    Last Post: 04-30-2007, 04:10 PM
  4. malloc, calloc question
    By chen1279 in forum C Programming
    Replies: 12
    Last Post: 09-07-2006, 05:54 PM
  5. Question about malloc()
    By cdalten in forum C Programming
    Replies: 6
    Last Post: 05-12-2006, 10:57 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21