title: Getting Segmentation Fault in Realloc
body: <p>Here i want to create dynamically memory.
  here i dnt know the output size and i want to print last final output after while loop.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  void main() {
  
      char *sdpCommand = "sdptool browse 04:18:0F:B1:48:B5";
  
      FILE *fp;
      fp = popen(sdpCommand, "r");
  
      char *results = 0;
      if (fp == NULL) {
          printf("Failed to run command\n");
          return;
      }
  
      char* buffer = malloc(514);
      while (fgets(buffer, strlen(buffer) - 1, fp) != NULL) {
          realloc(results, strlen(results) + strlen(buffer));
          memcpy(results + strlen(results), buffer, strlen(buffer));
      }
      printf("Output    :::  %s", results);
  
      /* close */
      pclose(fp);
      sleep(1);
  
  }
  </code></pre>