Thread: Make ptr

  1. #1
    Microsoft. Who? MethodMan's Avatar
    Join Date
    Mar 2002
    Posts
    1,198

    Make ptr

    Code:
    Node *MakeNode(StackEntry item)  
    {
      Node *nptr;
      if( (nptr = malloc ( sizeof nptr) ) != NULL)     
            {
            nptr = item;     
            return item;
            }
            else
                    return NULL;
    
    }
    warning: assignment makes pointer from integer without a cast
    warning: assignment makes pointer from integer without a cast
    warning: return makes pointer from integer without a cast

    I am getting these errors, can anyone tell me why, and make the corrections? Thanks

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    247
    Code:
    Node *MakeNode(StackEntry item)  
    {
      Node *nptr;
      if( (nptr = malloc ( sizeof nptr) ) != NULL)     
            {
            nptr = item;     
            return nptr;
            }
            else
                    return NULL;
    
    }
    Or
    Code:
    Node *MakeNode(StackEntry *item)  
    {
      Node *nptr;
      if( (nptr = malloc ( sizeof nptr) ) != NULL)     
            {
            nptr = item;     
            return item;
            }
            else
                    return NULL;
    
    }
    hoping to be certified (programming in c)
    here's the news - I'm officially certified.

  3. #3
    Microsoft. Who? MethodMan's Avatar
    Join Date
    Mar 2002
    Posts
    1,198
    I made the correction with the first correction of the code, and I get the same error

  4. #4
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    You should use malloc to make space for the size of the Node structure ?

  5. #5
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    This is a very strange function. The function receives the variable item, does nothing with it and returns item.

    What type is StackEntry? I think it is not the same type as Node, so you can't return item.

    Since your function should returns Node *, I assume you want nptr being returned. You can't assign nptr and item, I think that you want something like:

    nptr->item = item;

    That is, I assume Node is a structure with a member of type StackEntry and you want that member having the value of item.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to make a Packet sniffer/filter?
    By shown in forum C++ Programming
    Replies: 2
    Last Post: 02-22-2009, 09:51 PM
  2. Quick question concerning switch statements
    By Shaun32887 in forum C++ Programming
    Replies: 22
    Last Post: 08-02-2008, 11:33 AM
  3. Replies: 2
    Last Post: 07-16-2008, 05:01 PM
  4. Compiling c++ intrinsics commands
    By h3ro in forum C++ Programming
    Replies: 37
    Last Post: 07-13-2008, 05:04 AM
  5. Question about atheists
    By gcn_zelda in forum A Brief History of Cprogramming.com
    Replies: 160
    Last Post: 08-11-2003, 11:50 AM