W
whitehatmiracle
Hi all
Im not quite sure how to use the new and delete for a whole array
dynamically.
Actually i want that, a user inputs a char in a single char array.
Everytime he inputs a char he creates a new array of (previous size +
1), he then copies the content of the old array in to the new array
and adds the new input at the end and deletes the old array. I guess
he has to pass the pointer to the array everytime.
For example.
input: a
output a
input: b
output: a b
input c:
output a b c .
Any clues??????????????
i guess the code gotta be somthing like this:
int counter = 0;
int main(){
clrscr();
cout<<"Input a character: ";
get_char();
getch();
return 0;
}
get_char(){
ch = getch();
counter ++;
while (ch != -1){ ///exit if usr inputs -1
for (int i = 0; i<counter; i++)
dyn_array = old_array;
dyn_array[i+1] = ch;
delete[] old_array;
print_array(*ptr_to_dyn_array, counter)
}
print_array(*ptr, int){
for (int i = 0; i =<counter;i++){
}
}
Something like this ............!!!!!?????
Im confused.........?????????????
Im not quite sure how to use the new and delete for a whole array
dynamically.
Actually i want that, a user inputs a char in a single char array.
Everytime he inputs a char he creates a new array of (previous size +
1), he then copies the content of the old array in to the new array
and adds the new input at the end and deletes the old array. I guess
he has to pass the pointer to the array everytime.
For example.
input: a
output a
input: b
output: a b
input c:
output a b c .
Any clues??????????????
i guess the code gotta be somthing like this:
int counter = 0;
int main(){
clrscr();
cout<<"Input a character: ";
get_char();
getch();
return 0;
}
get_char(){
ch = getch();
counter ++;
while (ch != -1){ ///exit if usr inputs -1
for (int i = 0; i<counter; i++)
dyn_array = old_array;
dyn_array[i+1] = ch;
delete[] old_array;
print_array(*ptr_to_dyn_array, counter)
}
print_array(*ptr, int){
for (int i = 0; i =<counter;i++){
}
}
Something like this ............!!!!!?????
Im confused.........?????????????