QUOTE(Emper0r @ 6 Jun, 2007 - 10:13 PM)

QUOTE(rameshg87 @ 6 Jun, 2007 - 10:08 PM)

I think you are trying to print the contents of an array that already exists. If am not wrong in this, then there is no need of the malloc statement in the fuction printArray, because it allocates some new space for nElts of the array. Hence it will not print the contents of the array, because now the array pointer points to the first block of newly allocated space, not the old one. Hence if you remove that statement of malloc, it will print the contents of the array. You need to allocate memory only when you enter the elements.
Well actually this array is created in the function. I was thinking the malloc statement creates it, sounds like I'm doing something wrong lol. What am I missing as far as the array declaration goes?
Basically what rameshg87 said, you're taking in an array then trying to redefine the memory so either
A.) The pointer / array was empty/not allocated as you said, therefore you're printing out whatever is in the malloc'd space previously before you're populating the array or
B.) You're re-allocating the memory for the array as well as part A., printing out an empty array (or whatever was held in the memory previously before you malloc'd that memory).
Either way you're mallocing new space for an array which has nothing in it, if it was populated in another function before it was malloc'd then that memory isn't really safe and not considered yours until you malloc the pointer. I'd say try taking out the malloc statement, because it should already be allocated and populated if the only point of the function is to print out the array. I think the part you're confused about is what malloc is doing. A pointer just points to the first element in an array, but instead of creating a statically sized array, you can create a variable size array in your program using malloc. Until you malloc the memory, the memory after the first element doesn't belong to you're program and a lot of times will result in you're program core-dumping when you try to tamper with memory that doesn't belong to your program. Malloc is just reserving a set sized block of memory for you, it's not actually putting information in the array.