473,386 Members | 1,823 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,386 software developers and data experts.

please help with pointer

I've posted this in the learn c-c++ group as well. Can some please help me
with why the rooot pointer variable keeps changing. First it is what is
supposed to be then it just changes. Here are some excerpts of my code.
I made root a global variable pointer.

struct binaryNode *root;

The first thing I did was set it NULL in the main.
root = NULL;

Then I use a integer and my root as a arguments in my insert method to
create the a Tree.

void insert(int x, struct binaryNode *node)

{
if(root==NULL)

{

root = node;

root -> value = x;

}

.......

}//end of insert I've cut the function just like you see here and the root
still changes
This is how I call the insert method
.......

struct binaryNode tempNode = createNode();

insert(number, &tempNode);

.......

And here his the createNode function.
struct binaryNode createNode()

{

struct binaryNode *t;

t = (malloc(sizeof(struct binaryNode)));

return *t;

}

Any Help is appreciated.

Apr 25 '06 #1
3 1483
jova wrote:
I've posted this in the learn c-c++ group as well. Can some please help me
with why the rooot pointer variable keeps changing. First it is what is
supposed to be then it just changes. Here are some excerpts of my code.

This looks like C, not C++, try comp.lang.c. Also cross-post, rather
than post to multiple groups.

--
Ian Collins.
Apr 25 '06 #2
you'd better rewrite the createNode function(),it should return a
pointer not a struct just as you did.

Apr 25 '06 #3

"Nerazzurri" <ho*********@mail.csdn.net> wrote in message
news:11**********************@y43g2000cwc.googlegr oups.com...
you'd better rewrite the createNode function(),it should return a
pointer not a struct just as you did.


Thank You. That help very much. I'm jumping up and down. LOL
Apr 25 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: free2cric | last post by:
Hi, I attanded an interview on C++ Question asked were and my answers to them.. 1. In a CPP program what does memory leak occure? -- i said.. In a constructor , the pointer variables were...
11
by: Lues | last post by:
Hi, I'm trying to protect some data in tables with encription (you know why, don't you ;)) I must confess that I'm not very expirienced in writing code, especially encription code. Can any...
16
by: David Ford | last post by:
I have a macro that I use across the board for freeing ram. I'd like to clean up my code so I don't get these warnings. #define sfree(x) _internal_sfree((void **)&x) #define _internal_sfree(x)...
5
by: cpptutor2000 | last post by:
I am compiling and running the following code snippet on a Linux box - I am really puzzled by the answers. Could someone please tell me what might be wrong? void test(){ int m = 0; int n = 0;...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
9
by: Andreas Vinther | last post by:
I have a small piece of code that compiles but does not perform like I want it to. This code works: ---------------- void *y0; void *y1; void *y2; void *y3;
2
by: BarberCut | last post by:
hey guys! please help me answer these questions. i'm not a C++ programmer but my employer asked me to answer these questions ASAP. please help me. thanks. 1. What will I find in the value field...
1
by: rasmidas | last post by:
I have a function sEntityFree() which is a function from a third party S/w we are using. For this we have our enhanced code. sEntityFree() has been called inside our enhanced code 2000 or 3000...
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 ...
1
by: alan | last post by:
I have a set of classes, cell, cell_body, and cell_internal. cell_internal is an abstract base class, intended to encapsulate deferred computation. cell is just a wrapped pointer around...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.