Thread: help!!

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    8

    help!!

    can anyone tell me what's wrong with my code..

    here is the method..
    Code:
    PositionNode addPosNode(int posNum)
    {
       PositionNode *newNode;
       
       newNode = malloc(sizeof(PositionNode));
       
       if(newNode == NULL)
       {
          return NULL;
       }
       
       newNode->positionNum = posNum;
       newNode->nextPosition = NULL;
       
       return newNode;
    }
    it gives me error "incompatible types in return"

    and here is the structure definition
    Code:
    typedef struct positionNode
    {
       int positionNum;
       struct positionNode* nextPosition;
    } PositionNode;

  2. #2
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    The way you declared your function it is supposed to return a PositionNode but returns a pointer to a PositionNode.
    Make addPosNode() return a pointer.
    Like this
    Code:
    PositionNode * addPosNode(int posNum)
    Kurt

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    8
    it's works..

    thanks for ur help..

    im really really new in C.. maybe i can learn a lot from this site ^o~

Popular pages Recent additions subscribe to a feed