error in a function.needs help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • meetharry19
    New Member
    • Nov 2007
    • 7

    error in a function.needs help

    i m trying to make a function which will calculate size of each node of an ordered statistic tree . here size refers to the number of nodes in left sub tree and right sub tree plus one...
    but whenever i call this function compiler gives error....and program terminates at line:

    if(ptr->lc==NULL && ptr->rc==NULL)

    [code=c]
    size(struct node *ptr)
    {
    if(root==NULL)
    {

    return 0;
    }
    if(ptr->lc==NULL && ptr->rc==NULL)
    ptr->size=1;
    if(ptr!=NULL)
    ptr->size=(size(p tr->lc) + size(ptr->rc)+1);

    }
    [/code]

    plz help out by advising me
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Please use the [code]...[/code] tags provided.

    What compiler error do you get?

    What do you think this function does it it is called with a NULL pointer?

    Comment

    • meetharry19
      New Member
      • Nov 2007
      • 7

      #3
      Originally posted by Banfa
      Please use the
      Code:
      ...
      tags provided.

      What compiler error do you get?

      What do you think this function does it it is called with a NULL pointer?
      for your convenience ,to understand wat actually is done...i m putting the whole program :
      Code:
      <snipped>
      and the error is general protection exception and line :if(ptr->lc==NULL && ptr->rc==NULL) i.e. line no 68..
      is highlighted...i want to know what is wrong....

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        Originally posted by meetharry19
        and the error is general protection exception and line :if(ptr->lc==NULL && ptr->rc==NULL) i.e. line no 68..
        is highlighted...i want to know what is wrong....
        I have removed you code because a) it is against our posting guideline to post the full code solution to what may be a coursework problem and b) it is not required your original snippet contains all that is required to diagnose the problem.

        A "general protection exception" is not a compiler error it is a runtime error, getting the terminology right will help in getting your problem fixed.

        And I ask you again what do you think is happening in your function when it is called with a NULL pointer, i.e. when ptr == NULL? If it isn't obvious to you then I suggest you step through each line of code in the function on paper executing it as your processor would.

        Comment

        • SpecialKay
          New Member
          • Mar 2008
          • 109

          #5
          No its not dude,
          I believe the rules say, when you are asking a question it is alright to post entire code. The rules are asking the experts not to post entire code solutions, and that makes sence.

          edit:
          Sorry guess the rule was changed again. My bad... dont agree with it tho, if you are asking a question, should be aloud to post full code. anyways.

          Comment

          • meetharry19
            New Member
            • Nov 2007
            • 7

            #6
            Originally posted by SpecialKay
            No its not dude,
            I believe the rules say, when you are asking a question it is alright to post entire code. The rules are asking the experts not to post entire code solutions, and that makes sence.

            edit:
            Sorry guess the rule was changed again. My bad... dont agree with it tho, if you are asking a question, should be aloud to post full code. anyways.
            thank you for your valuable suggestions
            thanks for your valuable suggestions .....banfa

            Comment

            • Banfa
              Recognized Expert Expert
              • Feb 2006
              • 9067

              #7
              Originally posted by SpecialKay
              edit:
              Sorry guess the rule was changed again. My bad... dont agree with it tho, if you are asking a question, should be aloud to post full code.
              Nope they have been that way since about this time last year, I should know I wrote them :D

              It's like that for the protection of the poster as much as anything else.

              Comment

              Working...