- Joined
- Nov 28, 2001
ok heres what im doing, i have a temporary storage array temp[100] (any large number to hold user input)
i then have the user type in a sentence and store it in this array.
I then calculate how much of the array was actually used (call it NUM) and use that number to create a dynamically allocated array of size[NUM], i then copy the string over to the new vector and it works fine that array is now exactly only the size of the typed string (so if the user types in "hello" the new string is only 6 characters long vs the 100 for temp)
my question is i want to find a way so that if i put the user input into a function and call it say 3 different times, i can create 3 new dynamically allocated arrays (or not just 3 but however many times the user input function is called)
example
Hello world (1st input creates a dynamic arrayof size 12)
Hi (2nd input creates a dynamic array of size 2)
and so on...
my problem is in my code i have to define a name for the new array i.e.
char *vec;
vec = new char [size];
but when the user inputs the 2nd, 3rd, or Xth string, how can i create a name for the dynamic array?
I know this is a bit confusing hope someone out there can make sense of my rants
i then have the user type in a sentence and store it in this array.
I then calculate how much of the array was actually used (call it NUM) and use that number to create a dynamically allocated array of size[NUM], i then copy the string over to the new vector and it works fine that array is now exactly only the size of the typed string (so if the user types in "hello" the new string is only 6 characters long vs the 100 for temp)
my question is i want to find a way so that if i put the user input into a function and call it say 3 different times, i can create 3 new dynamically allocated arrays (or not just 3 but however many times the user input function is called)
example
Hello world (1st input creates a dynamic arrayof size 12)
Hi (2nd input creates a dynamic array of size 2)
and so on...
my problem is in my code i have to define a name for the new array i.e.
char *vec;
vec = new char [size];
but when the user inputs the 2nd, 3rd, or Xth string, how can i create a name for the dynamic array?
I know this is a bit confusing hope someone out there can make sense of my rants