dynamically created arrays

Posted by DevAno1 on Stack Overflow See other posts from Stack Overflow or by DevAno1
Published on 2010-04-26T21:54:38Z Indexed on 2010/04/27 10:53 UTC
Read the original article Hit count: 345

Filed under:
|
|
|
|

My task consists of two parts. First I have to create globbal char array of 100 elements, and insert some text to it using cin. Afterwards calculate amount of chars, and create dedicated array with the length of the inputted text. I was thinking about following solution :

char[100]inputData;

int main()
{  

   cin >> inputData >> endl;

   int length=0;
   for(int i=0; i<100; i++)
   {
           while(inputData[i] == "\0")
           {
               ++count;
           }
   }
char c = new char[count];

Am I thinking good ?

Second part of the task is to introduce in the first program dynamically created array of pointers to all inserted words. Adding a new word should print all the previous words and if there is no space for next words, size of the inputData array should be increased twice. And to be honest this is a bit too much for me. How I can create pointers to words specifically ? And how can I increase the size of global array without loosing its content ? With some temporary array ?

© Stack Overflow or respective owner

Related posts about c++

Related posts about arrays