Hello sorry if i hijack this thread for my own purpose, first English isent my first language, my apologies for the misspelling and all.
I also have problem with dynamic arrays, our stupied teacher made the assingment harder then he hade to. I'll try to explain the assingment.
First we are supposed to use dynamic arrays, like
int *list = new int;
And thats fine its nothing special about that, but he whants us to write a funktion that expands(s*) the dynamic array one integer at the time
void expandera_lista( int *&list , int n)
{
int *templist = new int[n];
for(int i=0; i<=n;i++)
{
templist[i] = list[i];
}
delete[] list;
list = new int[n+1];
for(int i=0; i<=n;i++)
{
list[i] = templist[i];
}
delete[] templist;
}
I think this code will work.
the problem is that i have to controll the size ( n ) of the array to make room for the next integer. I have tried
int n = (sizeof(*list)/sizeof(list[0]))
and that wont work it returns 1 att the time.
Does any one have a simpel ansver to my problem?