469,300 Members | 2,203 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,300 developers. It's quick & easy.

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)

Expand|Select|Wrap|Line Numbers
  1. size(struct node *ptr)
  2. {
  3.     if(root==NULL)
  4.     {
  5.  
  6.         return 0;
  7.     }
  8.   if(ptr->lc==NULL && ptr->rc==NULL)
  9.       ptr->size=1;
  10.     if(ptr!=NULL)
  11.     ptr->size=(size(ptr->lc) + size(ptr->rc)+1);
  12.  
  13.      }
  14.  
plz help out by advising me
Apr 23 '08 #1
6 1043
Banfa
9,064 Expert Mod 8TB
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?
Apr 23 '08 #2
Please use the
Expand|Select|Wrap|Line Numbers
  1. ...
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 :
Expand|Select|Wrap|Line Numbers
  1. <snipped>
  2.  
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....
Apr 23 '08 #3
Banfa
9,064 Expert Mod 8TB
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.
Apr 23 '08 #4
SpecialKay
109 100+
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.
Apr 23 '08 #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.
thank you for your valuable suggestions
thanks for your valuable suggestions .....banfa
Apr 23 '08 #6
Banfa
9,064 Expert Mod 8TB
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.
Apr 23 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Wayno | last post: by
3 posts views Thread by Victor | last post: by
5 posts views Thread by sriram | last post: by
4 posts views Thread by Issac | last post: by
1 post views Thread by mario.zoric | last post: by
4 posts views Thread by cpptutor2000 | last post: by
12 posts views Thread by jonatan | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.