Can anyone help me? My program keeps crashing after 2 inputs..

Someone help please... this code keeps crashing after i input 2 strings for the array i created. i cant find out why its crashing... :(

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
  Write a program containing the following functions, in this order:
main - calls the other functions; otherwise does almost nothing
getSize - which asks the user how many strings they want
getSpace - which gets an array in the heap of the size requested by the user
inputData - which allows the user to input the strings and stores them
in the array
printData - which prints all the strings, one string per line
destroy - which returns all the space to the heap

All of these functions, except main, shall have a return type of void.


/* Calls the other functions; otherwise does almost nothing */

int main ()
{
    int numStrings;

    string newArray;

    getSize (&numStrings);

    getSpace (&numStrings, &newArray);

    inputData (&numStrings, &newArray);

    return 0;
}

/*getSize - which asks the user how many strings they want */
void getSize (int *numStrings)
{
    cout << "How many strings would you like? " << endl;
    cin >> *numStrings;
}

/*getSpace - which gets an array in the heap of the size requested by the user */
void getSpace (int *numStrings, string newArray[] )
{
    newArray = new string [*numStrings];
}

/* inputData - which allows the user to input the strings and stores them */
void inputData (int *numStrings, string newArray[])
{
    string data;
    for (int i = 0; i < *numStrings; i++)
    {
        cout << "Please enter string #" << i << endl;
        cin >> data;
        newArray[i] = data;
        cout << newArray[i] << endl;
    }
Please, do not double post. It clutters forums and spreads attempts to help you. Another thread: http://www.cplusplus.com/forum/general/168657/
Topic archived. No new replies allowed.