title: malloc.c: No such file or directory
body: <p>I am trying to write a program in C which accepts a stream of inputs and break the input based on the occurrence of spaces in the string and creates a 2-D array from them. e.g.</p>
  
  <p>If input is :</p>
  
  <p><code>this is cat</code></p>
  
  <p>Output:</p>
  
  <p><code>this</code><br />
  <code>is</code><br />
  <code>cat</code><br /></p>
  
  <p>My code is as follow:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;malloc.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main(){
  int ** a;
  int * element;
  int i;
  int size = 2;
  int element_size = 2;
  int element_count = 0;
  char c;
  int flag = 0;
  
  if((a = (int **)calloc(size, sizeof(int **))) == NULL){
      printf("Not enough space");
      exit(0);
  }
  for(i = 0; i &lt;= size; i++){
      element_size = 2;
      element_count = 0;
      flag = 0;
      if(i &gt;= size){
          size *= 2;
          if((a = (int **)realloc(size, sizeof(int **))) == NULL){
              printf("Not enough space");
              exit(0);
          }
      }
      if((element = (int *)calloc(element_size, sizeof(int *))) == NULL){
          printf("Not enough space");
          exit(0);
      }
      while(1){
          c = getchar();
          if(element_count &gt;= element_size){
              element_size *= 2;
              if((element = (int *)realloc(element_size, sizeof(int *))) == NULL);
          }
          if(c == ' '){
              flag = 0;
              break;
          }
          else if(c == '\n' || c == '\0' || c == '\r'){
              flag = 1;
              break;
          }
          else{
              element[element_count] = (char)c;
              element_count++;
          }
      }
      element[element_count] = '\0';
      *a[i] = element;
      if(flag == 1)break;
  }
  for( i = 0; i &lt; size; i++){
      printf("%s\n", *a[i]);
  }
  return 0;
  }
  </code></pre>
  
  <p>This code is giving runtime error <code>SIGSEV</code> with coredump.</p>
  
  <p>Analysis of core dump with gdb shows:</p>
  
  <p><code>Program terminated with signal SIGSEGV, Segmentation fault. #0  __GI___libc_realloc (oldmem=0x4, bytes=8) at malloc.c:2977
  2977    malloc.c: No such file or directory.</code></p>
  
  <p>What does this error mean?</p>
  
  <p>It would be very helpful if one can point out error in my code or any new method of do so.</p>