1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Getting Confusing Output

Discussion in 'C' started by micsom_micsom, Nov 3, 2009.

  1. micsom_micsom

    micsom_micsom New Member

    Joined:
    Mar 23, 2009
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Embedded C Programmer
    Location:
    India,Hybd
    Hi i am getting a wierd output when i execute this function..Node is a structure
    Head can be 1/0...if i give 1, its entering into if(Head == 1)..but then Head's value is changed to 1nNumber(12,13,...the second digit is nNumber). i suspect somehow the stack is getting curropted but not able to find out whr,how..
    Code:
    int Check_CreateNumberNode(const int Head,int nNumber,Node* pNode,Node** ppNode)
    {
      int nRetVal=0;
      if(NULL == *ppNode)
      {
       return 1;
      }
      printf("\nCheck_CreateNumberNode");
      
      if(Head == 1)
      {
            (*ppNode)->Carry=0;
            (*ppNode)->Number=nNumber;
            (*ppNode)->pPrev=NULL;
            (*ppNode)->pNext=NULL; 
            printf("\nHead1=%d",Head);
      }else if(Head == 0)
      {
            (*ppNode)->Carry=0;
            (*ppNode)->Number=nNumber;
            (*ppNode)->pPrev=pNode;
            (pNode)->pNext=(Node*)*ppNode;
            (*ppNode)->pNext=NULL;  
            printf("\nHead0=%d",Head);
      }
    
    
      return nRetVal;
    }
     
    Last edited by a moderator: Nov 4, 2009
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    Insufficient code to determine the problem. Create a minimal testbed that defines Node, and sets up a main function that initialises the smallest possible numberr of Node variables to reproduce the problem, and call Check_CreateNumberNode from that main function. Then post the complete code.
     
  3. micsom_micsom

    micsom_micsom New Member

    Joined:
    Mar 23, 2009
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Embedded C Programmer
    Location:
    India,Hybd
    i was suspecting the problem is with this functon only, but it turned out there was no probs..its my mistake only...
     

Share This Page