title: Resizing character array in c
body: <p>A MFC coder want to learn some basic about character array intialisation and deletion of element.Take following examples compare with MFC (there is CString so no need of memory allocation or de allocation but same needed in c.)
  <strong>(don't have std::string interface )</strong></p>
  <p><em><strong>Example 1:-</strong></em></p>
  <p>To construct string we us following code in MFC.</p>
  <pre><code>CString constructString;    
  constructString = &quot;&quot;;    
  constructString = &quot;ABC&quot;;    
  constructString = constructString + &quot;PQR&quot;;    
  constructString = constructString + &quot;LMN&quot;; 
  </code></pre>
  <p>whatever size of string we have this will work.</p>
  <p>for C i used following code</p>
  <pre><code>#define DEFAULT_ARRAY_SIZE          20000    
  char* constructString  = new char[DEFAULT_ARRAY_SIZE];    
  strcpy(constructString ,&quot;&quot;);    
  strcat(constructString ,&quot;ABC&quot;);    
  strcat(constructString ,&quot;PQR&quot;);    
  strcat(constructString ,&quot;LMN&quot;);
  </code></pre>
  <p><em><strong>Problem :-</strong></em></p>
  <p>1)Code will work fine till my char* constructString size is less than 20000 but when it exceed i dont have solution,how to resize my array so it will take more charecters.</p>
  <p>2)I intialize char* constructString with 20000 but when my string is very small of size 10 then my remaining 18990 charecters are wasted or not i dont know,will this effect my executable perfomance.If yes then how to delete my remaining dummy charecters.</p>
  <p><em><strong>Example 2:-</strong></em></p>
  <p>To read content from file we use following code in MFC.</p>
  <pre><code>CStdioFile ReadFile;    
  ReadFile.Open(&quot;Sample.txt&quot;,CFile::typeText|CFile::Read);    
  CString CurrentString;    
  CStringArray WholeFile;    
  while(ReadFile.ReadString(CurrentString))    
  {    
      WholeFile.Add(CurrentString);    
  }
  </code></pre>
  <p>Whitever size of File it will work fine.</p>
  <p>For C i use following code</p>
  <pre><code>#define MAX_FILE_SIZE               65534    
  FILE *ptr_file;    
  const char* list[MAX_FILE_SIZE];    
  wchar_t CurrentString[1000];    
  ptr_file =fopen(&quot;Sample.txt&quot;,&quot;rb&quot;);    
  int __index = 0;    
  while(fgetws (CurrentString , 1000 , ptr_file) != NULL)    
  {    
      char* errorDes;    
      errorDes = new char[1000];    
      wcstombs(errorDes, CurrentString, 1000);    
      list[__index] = errorDes;    
      __index++;    
  }
  </code></pre>
  <p><em><strong>Problem :-</strong></em></p>
  <p>1)Same as above if my one line charecters exceed 1000 then more than 1000 charecters are not consider and vise versa.</p>
  <p>2)If my file size exceed 65534 then char* list array will not fill properly and vise versa.</p>
  <hr />
  <p>Please provide me any link,block of code,suggestion that help me to solve all problem in pure C.</p>