Re: how to replace a substring in a string using C?
- From: Skarmander <invalid@xxxxxxxxxxxxxx>
- Date: Sun, 30 Oct 2005 21:46:46 +0100
Netocrat wrote: <snip>
char *replace(const char *s, const char *old, const char *new)
{
<snip>
ret = malloc(i + count * (newlen - oldlen)); if (ret == NULL) exit(EXIT_FAILURE);
Whoa, what's this? Just return NULL. It's massively rude to terminate the program in a function like this. It's *likely* the caller can't respond to out-of-memory either (and won't check for it if they're sloppy), but making the decision here is silly.
S. .
- Follow-Ups:
- Re: how to replace a substring in a string using C?
- From: Netocrat
- Re: how to replace a substring in a string using C?
- References:
- Re: how to replace a substring in a string using C?
- From: Netocrat
- Re: how to replace a substring in a string using C?
- Prev by Date: Re: how to replace a substring in a string using C?
- Next by Date: Re: how to replace a substring in a string using C?
- Previous by thread: Re: how to replace a substring in a string using C?
- Next by thread: Re: how to replace a substring in a string using C?
- Index(es):
Relevant Pages
|