Re: strdup/strcpy

From: Brian (borlick@mines.edu)
Date: 11/06/02


Mathew Earle Reuther wrote:
>
> On Thu, 7 Nov 2002, Mark Garringer wrote:
>
> > I seem to be having a really hard time with this, so I hope someone can give
> > me a quick answer (and maybe a slap on the head).
>
> Seems to me this problem bothered me briefly when I changed to multiple
> money types as well.  I fixed it with snprintf() . . .
>
>     snprintf(buf, sizeof(buf), "%s", money_info[type].single_namelist);
>     obj->name = strdup(buf);

That's a slight bit of overkill.  It should be sufficient to just do:

      obj->name = strdup(currency_types[cur]);

And somewhere else define:

const char *currency_types[] =
 { "coins gold",
   "coins platinum",
   .
   .
   .
 };

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   | Newbie List:  http://groups.yahoo.com/group/circle-newbies/   |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 06/25/03 PDT