title: Getting (core dumped) when using realloc
body: <pre><code>void replace(char *str) {
      unsigned int len = 0;
      unsigned int no_of_spaces = 0;
      while (*str) {
          if ((char)*str == SPACE)
              no_of_spaces++;
          str++;
          len++;
      }
  
      unsigned int new_len = len + 2 * no_of_spaces;
      str = (char*) realloc(str, new_len * sizeof(char));
      str[new_len] = '\0';
  }
  </code></pre>
  
  <p>I use function like <code>replace("random string");</code>.</p>
  
  <p>Here I am trying to increase the size of the string so that spaces can be replaced with another string. For this I need to count the no of spaces and also get the length of the original string. I have been able to do that.</p>
  
  <p>For resizing I am using <code>realloc</code> but when I run it, it gives <code>Aborted (core dumped)</code>?</p>