I finally got around to getting this to you: Keith's programming blog: C and C++ Array Intricacies It's not my best writing, so I would appreciate comments/questions.
Type: Posts; User: pantherse
I finally got around to getting this to you: Keith's programming blog: C and C++ Array Intricacies It's not my best writing, so I would appreciate comments/questions.
Let me restate, that's MY usual way. This is from the malloc/calloc manpage:
That's the reason why I prefer to use calloc() when allocating arrays. I find it clearer to read, and you don't run the...
Okay, here's the stuff to fix your code as it stands so it'll work. As for funny pointer tricks, I'll post a link at a later time.
First, change:
myPtr = (int*) malloc(intValue + 2); to
myPtr...
From the way your code looks, you seem to expect myPtr to be used as an int array. Which means, they way you allocated the memory for myPtr
myPtr = (int*) malloc(intValue + 2); is wrong because...