title: Error when deleting a pointer that has been declared as new?
body: <p>I am writing a program right now that alters a <code>C_String</code> using pointers to the string. I have an implementation that works fine. The only problem I am running into is that when I reach the end of my program, if I try to delete the pointers I get an error. </p>
  
  <p>My code:</p>
  
  <pre><code>void CStringSwitcher()
  {
  
      string input = "";
      char* cStringArray = new char[ASIZE];
      char* reversed = new char[ASIZE];
      const char* originalReversed = reversed;
      char* pointers[POINTER_SIZE];
      memset(reversed, '\0', ASIZE);
      memset(cStringArray, '\0', ASIZE);
      memset(pointers, '\0', POINTER_SIZE);
      char* current = cStringArray;
      cout &lt;&lt; "Enter a sentence on each line. Input a 0 to stop." &lt;&lt; endl;
  
      // Receives input from the user and stores it into cStringArray
      int i = 0;
      do
      {
          cout &lt;&lt; "&gt;";
          cin.clear();
          fflush(stdin);
          input = "";
          getline(cin, input);
          if (input == "0")
              break;
          else
          {
              input.append("\n");
              pointers[i] = current;
              _CRT_SECURE_STRCPY(pointers[i], ASIZE - 1, input.c_str());
              current += input.length();
              i++;
          }
      } while(i &lt; POINTER_SIZE);
      char* end = current;
  
      --i;
      do
      {
          /// Check if done
          if(i &lt; 0)
              break;
          /// Copy from current to end
          current = pointers[i];
          do
          {
  
              *reversed++ = *current++;
          }while(current &lt; end);
          /// Update end
          end = pointers[i];
          /// Update i
          --i;
      }while(true);
      *reversed = '\0';
      cout &lt;&lt; endl &lt;&lt; originalReversed &lt;&lt; endl;
      system("PAUSE");
      //delete[] originalReversed;
      //delete[] cStringArray;
      return;
  }
  </code></pre>
  
  <p>As it is written above the code works fine, however if I uncomment the two delete lines just before the return I was getting an error:</p>
  
  <blockquote>
    <p>Project_06.exe has initiated a breakpoint</p>
  </blockquote>
  
  <p>and the program crashes. Weird thing is I just ran the program again to get the exact wording of the error message and it runs with no error? Any ideas on why that is?</p>