473,406 Members | 2,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 1261
Banfa
9,065 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,065 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,065 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

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

Similar topics

1
by: Wayno | last post by:
My php logs are coming up empty. I have done all I can think of, and all that made sense to me. Can someone take a look at my php.ini please and tell me what you think may be the problem. I...
3
by: Victor | last post by:
I'm trying to run this java program, but somehow the program always quit w/o giving any error msg at all. it happenned inside the first case statements. Strangely, after printing happen2, it just...
5
by: sriram | last post by:
I have the following: class BSA { ... ... ... ... public: enum VRGAttrId {
8
by: Dalan | last post by:
Please help - just take a quick look at the function code below. It probably just needs some minor tweaking. The function module is based on an intermediate query to provide a group record...
0
by: drumdawg21 | last post by:
Ive been working on this problem for a long time now and really need some help. I have a program in c++ code that gives me build errors and my program is having problems. I have two source files in...
4
by: Issac | last post by:
Hi, I am working on error handling for my project. I got the following code from the web which declare that it can catch all exceptions in my project rather that using TRY CATCH in everything...
1
by: mario.zoric | last post by:
Hi to all! I have one big problem. I have written some code and I want to program at the end looks good but theres one uninspected error. What's going on? I have written code for programm that...
2
by: dasilva109 | last post by:
Hi guys I am new to C++ and need urgent help with this part of my code for a uni coursework I have to submit by Thursday //ClientData.h #ifndef CLIENTDATA_H #define CLIENTDATA_H #include...
4
by: cpptutor2000 | last post by:
Could someone please help me? I have the following C struct. typedef struct _FIREWALL_RULE_INFO { ULONG Precedence; BOOL bEnabled; BOOL ...
12
by: jonatan | last post by:
Hello All, I am making a program and need the grt_main.c but i try to compile have the error c1004.Please help me how to solve it? Thank you. --------------------Configuration: pre - Win32...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.