[CODE] calling char function from sprintf

From: Artovil (artovil@arcanerealms.org)
Date: 09/05/01


I have been wrestling with my MySQL conversion now for a week or so, and
everything is going quite well, I already got actions into MySQL, including
the OLC part of it.

One thing though, I sent a couple of questions a week or so ago about
escaping ' from strings.  I think Mike supplied a void, but I needed a
char, so he sent me one off-list.  We have used that and remodeled it
slightly, and it seems to work ok, but for one thing.

When I use it in a sprintf all the values set with the char function end up
being the same.  What am I doing wrong?

Here's a faked query string:
     sprintf(query_str, "REPLACE INTO %s SET "
         "Name = '%s', "
         "Password = '%s', "
         "Email = '%s', "
         "Title = '%s', "
         "Description = '%s';"
Notice the escape_quotes().  When they are called within the sprintf both
title and description are set to the same value.

The actual char function:
char *escape_quotes(char *source) {
   static char dest[MAX_STRING_LENGTH * 2];
   *dest = 0;
   if (!source) {
     return ""; /* Error */
   }  else {
     while (*source) {
       if (*source == '\'')
         strcat(dest, "\\\'");
         strncat(dest, source, 1);
   return dest;

Can anyone help me?

Kind regards,

   | 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