in C. For what reason global point variable can lose its value after function exits?
global pointer variable i mean
Do you mean how can a global pointer lose its value after a function (in which it is used) exits? If so, imagine this scenario: -You declare a global pointer in some header file and initialize it/point it to some value. -In a function, while doing some kind of calculation you set the pointer to some address of a variable you created *inside* the function. -Once the function exits, all of the variables you created during that function's execution are taken off the stack; their memory is no longer addressable. Is this the kind of scenario you're talking about?
not exactly. I have tho fns that executes one after another. at the end of the 1st function I change global pointer variable value and I print it to see the value. At the beggining of the function 2 I print pointer's value and it is just junk from memory, my value is not saved. No code between fnction calls. So it is kind of when function 1 ended the global pointer value ( or pointer itself) changed.
Are you sure you aren't setting the pointer to the address of some variable that's declared and initialized inside the first function? Did you allocate memory for the data that the pointer points to so that data you create in one function can persist to others? It seems to me that your problem lies with the location of where the pointer is pointing, so I think that's the first place to double check.
By allocating memory, I mean using malloc() or something similar that lets you put stuff on the heap.
yes, I use malloc(). and I checked code, but i'm pretty new in C, so i might missed something. I know it is hard to help w/o seeing the code. but thanks anyway, i'll double check what location the pointer points.
http://pastebin.com/Hi0LfyFW there are lost of junk functions right now. take a look on loadFile() and then print() loadFile also uses insert()
would be great to use gdb for problems like this :-D I'll try
the problem with gdb, that i use pipe to get text file into this program, and gdb doesn't understand pipes...
use dynamic allocation using malloc ,calloc then make sure that u are not manipulating the pointer..
It seems thers is prob with typedef as both NODE and Node chaning the type of Datatype.... @agdgdgdgwngo
Join our real-time social learning platform and learn together with your friends!