title: C++: Heap corruption detected after normal block
body: <p>I am assigned with a task in which I should create some functions that does  some tricks on char arrays. So I created those functions and I was trying to see if they are working  correctly when I got stuck with this "HEAP CORRUCPTION DETECTED" error. </p>
  
  <p>Here is the code of my function</p>
  
  <pre><code>void cagir(char cDizi[], short int baslangic, short int karSayisi, char cDondur[])
  {
      //Yerel Değişken
      short int index = 0;
  
      /*Diziyi baslangic değerinden başlayarak, NULL karakterine ulaşılmadığı ve baslangic değeri 
        baslangic + karSayisi'na eşit ya da küçük olduğu sürece oku                              */
      for (; cDizi[baslangic] != '\0' &amp;&amp; baslangic &lt; baslangic + karSayisi; baslangic++)
      {
      //Okunan karakteri cDöndür dizisine yerleştir
      cDondur[index] = cDizi[baslangic];
      index += 1;  //cDöndür dizisinin index'ini 1 artır
      }
  }
  </code></pre>
  
  <p>What I am trying to do here is basicly getting the specified amount of characters from 'cDizi' and  put them in the other precreated array 'cDondur'. The array 'cDizi' is an array of user input, and  'cDondur' is an array created in the related part of the program. I wanted to assign the number of  characters to be called as the range of the array 'cDondur'.</p>
  
  <p>Here is the part I call the function in my program, and create the 'cDondur' array</p>
  
  <pre><code>case '3':  //MOD - 3
      {
  
             short int indis, karSayisi;
  
             //Çağrılacak parçanın ilk karakterinin indisini öğren
             cout &lt;&lt; "Almak istediğiniz ilk karakterin indisi : ";
             cin &gt;&gt; indis;
  
             //kaç karakterlik parça çağrılacağını öğren
             cout &lt;&lt; indis &lt;&lt; " indisli karakterden itibaren almak istediğiniz karakter sayısı : ";
             cin &gt;&gt; karSayisi;
  
             //Sınırı karSayisi olan bir dizi oluştur
             char *Dizi = new char[karSayisi];
  
             //Parça çağırma fonksiyonunu çağır
             cagir(cDizi, indis, karSayisi, Dizi);
  
             cout &lt;&lt; endl;
  
             cout &lt;&lt; "İstediğiniz karakterler çağrıldı : ";
  
             //cagir fonksiyonunun sonucu olan 'Dizi' dizisini ekrana yaz
             for (int i = 0; i &lt; karSayisi; i++)
                 cout &lt;&lt; Dizi[i];
  
             delete Dizi;
  
             break;
      }
  </code></pre>
  
  <p>karSayisi here is the amount of characters I am going to get from the array and elemanSayisi(ARRAY) is a function that returns the amount of characters of its parameter.</p>
  
  <p>I really need to find a way to fix this quickly, and I have been working on the code for like 3 hours  straight to fix it but couldn't find anyway to do so.</p>