C++ dynamic arrays and functions

6 replies [Last post]
jons0n
jons0n's picture
Offline
Neophyte
Joined: 2010/02/03

what i want to do is output scores[] from getInput() into main(). the dynamic array will not cin past scores[0] without crashing. what am i doing wrong? i have gotten this code to run correctly within a single function, but i want to move the array between multiple functions.

void getInput(int * scores[], int * n, int & index)
{
        int i;
        bool sentinel=0;
<code>
        for(index=0; sentinel==0; index++)
        {
                cin >> *scores[index];
<code>
                if(*scores[index]==-999) { sentinel++; }
        }
}
<code>
int main()
{
        int n,
             index;
<code>
        int * scores = new int [n];
<code>
        getInput(&scores, &n, index);
}