[gameprogrammer] passing pointer to array

Hello,

I'm currently writing a mergesort for school (yes i know nothing directly related to gamedev but maybe you can help) and got a bit confused.

I have a pointer (in the main-function): int *numbers = 0;

a function for reading int values from a file:
int fileToArray(std::string filename, int *numbers, int &len);
in the function i allocate memory for the numbers:
numbers = new int[len];

I want to use both the length and the numbers in the main function,
but when I try to print them i get either an exeption, or the memory adresse:
for(int i = 0; i < len; ++i){
   std::cout<<numbers[i]; //exeption
   //std::cout<<&numbers[i]; //strange output (propably the adresses)
}

This is how i call the function:
if(fileToArray(filelist[fi], numbers, len))
{...}

Can anybody please tell me what I have done wrong?

Thanks in advance
Christoph




---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html


Other related posts: