Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Note, try to edit your code to get rid of the html escape codes.</strong></p> <p>Well, though it has been a while since I used C/C++, realloc that grows only reuses the memory pointer value if there is room in memory after your original block.</p> <p>For instance, consider this:</p> <p>(xxxxxxxxxx..........)</p> <p>If your pointer points to the first x, and . means free memory location, and you grow the memory size pointed to by your variable by 5 bytes, it'll succeed. This is of course a simplified example as blocks are rounded up to a certain size for alignment, but anyway.</p> <p>However, if you subsequently try to grow it by another 10 bytes, and there is only 5 available, it will need to move the block in memory and update your pointer.</p> <p>However, in your example you are passing the function a pointer to the character, not a pointer to your variable, and thus while the strrep function internally might be able to adjust the variable in use, it is a local variable to the strrep function and your calling code will be left with the original pointer variable value.</p> <p>This pointer value, however, has been freed.</p> <p>In your case, input is the culprit.</p> <p>However, I would make another suggestion. In your case it looks like the <em>input</em> variable is indeed input, and if it is, it shouldn't be modified, at all.</p> <p>I would thus try to find another way to do what you want to do, without changing <em>input</em>, as side-effects like this can be hard to track down.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload