help!!

This is a discussion on help!! within the C Programming forums, part of the General Programming Boards category; can anyone tell me what's wrong with my code.. here is the method.. Code: PositionNode addPosNode(int posNum) { PositionNode *newNode; ...

  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
    ZuK
    ZuK is offline
    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

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