#include <iostream>
#include <fstream>
#include <cstring>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <limits>
using namespace std;
void call(int i, int * test)
{
cin >> test[i];
}
int main()
{
int sizeOfArray;
int *temp;
int i;
cin >> sizeOfArray;
int * test;
string * command;
command = new string[sizeOfArray];
test = new int[sizeOfArray];
for (int i=0; i<sizeOfArray ;) {
cin >> command[i];
if (command[i] == "call"){
call(i,test);}
i++;
if (i >= sizeOfArray) {
sizeOfArray = sizeOfArray * 2;
int* temp = new int[sizeOfArray];
for (int p=0; p<i; p++) {
temp[p] = test[p];
cout << temp[p] << endl;
}
delete [] test;
test = temp;
}
}
system("PAUSE");
}
this is my entire code,
i want the array expand when the memory used up, so that i can infinitely input number to it and it will output all it stores.
however, here is the result, input is bolded:
1
call 1
1
call 2 // <-- once i press enter ,my program got error here and terminate
try another input:
2
call 1
call 2
1
2
call 3// <-- again, the program terminate when i press enter
WHats wrong with my code... i need help!!!!!