title: Realloc changes values, why?
body: <pre><code>int **arkadas;
  int **komsu;
  
  komsu = malloc( t*sizeof( int* ));
  arkadas = malloc( t*sizeof( int* ));
  
  for(i=0; i&lt;t; i++)
  {
      x=0;
      komsu[i] = malloc( t*sizeof(int) );
      arkadas[i] = malloc( t*sizeof(int) );//temporary malloc
  
      for(j=0; j&lt;t; j++)
      {
          komsu[i][j]=fark(kelime[i],kelime[j]);
          if(komsu[i][j]==1)
          {
              komsuSayisi++;
              x++;
              arkadas[i][x]=j;
          }
      }
      if(i==2)
      {
          printf("1. value: %d\n",arkadas[2][2]);
      }
      arkadas[i][0]=x+1;//size here
      if(i==2)
      {
          printf("2. value: %d\n",arkadas[2][2]);
      }
      arkadas[i] = (int *)realloc(arkadas[i],x+1);
      if(i==2)
      {
          printf("3.value: %d\n",arkadas[2][2]);
      }
  }
  </code></pre>
  
  <p>Outputs are those:</p>
  
  <pre><code>1. value: 150
  2. value: 150
  3. value: 13243564 (after realloc)
  </code></pre>
  
  <p>I want to convert a matrix into simple matrix, with losing the ones which are <code>0</code> in <code>komsu</code>. In <code>arkadas</code> only <code>1</code> ones. But as you can see, after <code>realloc</code> values changed. Only one and second one of array stays without changing.</p>