LiquidG
08-02-2002, 01:02 PM
After several a printf command, I've come along something very strange in my code ... I have a couple functions, as follows:
foo1()-- returns a value for a built in data type
foo2() -- returns a pointer to an array of values of the same built in data type as above (lenth of array passed as param)
foo3() -- prints out the array, under specified format
The problem that i'm having is in my main() function, i'm calling foo2, which in turn calls foo1 ... the output is as expected. But, when i call foo3, and pass to a pointer that foo2 returns, a printf of the passed parameter shows that its been altered! ... no where else in my code to i write to the array, and when i do my printf calls to verify the outputs, i make sure to do so by assigning a temp var first to equal the param/return in question.
Any suggestions? I'm assuming that I'm forgetting something bout ptr access in C, and I come from a humble C++ ... so my C is a little shakey right now.
foo1()-- returns a value for a built in data type
foo2() -- returns a pointer to an array of values of the same built in data type as above (lenth of array passed as param)
foo3() -- prints out the array, under specified format
The problem that i'm having is in my main() function, i'm calling foo2, which in turn calls foo1 ... the output is as expected. But, when i call foo3, and pass to a pointer that foo2 returns, a printf of the passed parameter shows that its been altered! ... no where else in my code to i write to the array, and when i do my printf calls to verify the outputs, i make sure to do so by assigning a temp var first to equal the param/return in question.
Any suggestions? I'm assuming that I'm forgetting something bout ptr access in C, and I come from a humble C++ ... so my C is a little shakey right now.