# _CP_str_realloc

_CP_str_realloc reallocates a CPSTR*
to a new length.

## Syntax

```
CPSTR* _CP_str_realloc(CPSTR* old, int expression)
```

## Parameter(s)

| old | Points to the string to reallocate. |
| --- | --- |
| expression | New length desired. |
If the request is for a smaller length than the current
one, or if the request is for a larger length, but the system senses
that the internal buffer size of the old CPSTR* is sufficient to handle
the extra length, then the routine changes the size and returns a
pointer equal to *old*. If the requested size is
too big for the internal buffer, then a new pointer is created, the
old data copied to the new one, and the old string released. Any new
buffer space not filled in by the old copy is undefined.

Note: The pointer allocated by _CP_str_realloc must
eventually be released by calling _CP_str_free,
not free().

## Example(s)

```
CPSTR * s = _CP_mkstr("hi");
s = _CP_str_realloc(s, 3);
_CP_SADDR(s)[2] = ’!’;
```

## See also

- [C functions overview](https://d3codex.com/cfunctions/c-functions-overview/)
- [_CP_str_alloc](https://d3codex.com/cfunctions/cp-str-alloc/)
- [_CP_str_free](https://d3codex.com/cfunctions/cp-str-free/)

---
Source: https://d3codex.com/cfunctions/cp-str-realloc/ - part of the D3Codex reference.
