By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
461,995 Members | 558 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 461,995 IT Pros & Developers. It's quick & easy.

error in a function.needs help

P: 8
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
Share this Question
Share on Google+
6 Replies

Banfa
Expert Mod 5K+
P: 8,968
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

P: 8
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
Expert Mod 5K+
P: 8,968
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

100+
P: 109
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

P: 8
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
Expert Mod 5K+
P: 8,968
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.