Re: [CODE] calling char function from sprintf

From: Mike Breuer (mbreuer@new.rr.com)
Date: 09/05/01


From: "Cathy Gore" <cheron@ARCANEREALMS.ORG>
> char *escape_quotes(char *source)
> {
>   char target[MAX_STRING_LENGTH * 2];
>
>   if (source == NULL)
>     return "\\\0";
You probably should replace the above line with:
    return str_dup("\\\0");

So that the user is always required to free the returned pointer.
Personally, I prefer functions that allocate and free their own memory to
functions that require you to free it, but this method will work if used
responsably.

>   string_to_store(target, source);
>
>   return (str_dup(target));  file://ya, it's a hack, but it works.
> }

<DISCLAIMER>
Also, please note that although I wrote the string_to_store() function, I
don't really endorse this usage, since there is a more effective API already
available for translating database strings.
</DISCLAIMER>

Mike

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/06/01 PST