>From owner-circle@post.queensu.ca Thu Aug 6 16:22:14 1998 >Received: from post.queensu.ca (post [130.15.126.6]) > by post.queensu.ca (8.9.0/8.9.0) with ESMTP id TAA09774; > Thu, 6 Aug 1998 19:05:27 -0400 (EDT) >Received: from POST.QUEENSU.CA by POST.QUEENSU.CA (LISTSERV-TCP/IP release > 1.8c) with spool id 994224 for CIRCLE@POST.QUEENSU.CA; Thu, 6 Aug > 1998 19:05:26 -0400 >Received: from pop.montana.com (pop.montana.com [199.2.139.66]) by > post.queensu.ca (8.9.0/8.9.0) with ESMTP id TAA09765 for > <CIRCLE@post.queensu.ca>; Thu, 6 Aug 1998 19:05:24 -0400 (EDT) >Received: from montana.com (nielsenj@gtf1-31.montana.com [208.4.229.31]) by > pop.montana.com (MX-9/8.9.0) with ESMTP id RAA06568 for > <CIRCLE@post.queensu.ca>; Thu, 6 Aug 1998 17:03:05 -0600 (MDT) >X-Mailer: Mozilla 4.05 [en] (Win95; I) >MIME-Version: 1.0 >References: <Pine.BSD.3.91.980806155002.28456A-100000@almond.elite.net> >Content-Type: text/plain; charset=us-ascii >Content-Transfer-Encoding: 7bit >Message-ID: <35CA3671.62D42@montana.com> >Date: Thu, 6 Aug 1998 17:04:17 -0600 >Reply-To: Circle Discussion List <CIRCLE@post.queensu.ca> >Sender: Circle Discussion List <CIRCLE@post.queensu.ca> >From: Jon Nielsen <nikolai@MONTANA.COM> >Subject: Re: Kingdom function >To: CIRCLE@post.queensu.ca > >TDRD wrote: > >> char *king(struct char_data * chh, char *cp, int p) >> { >> char *kingdo; >> kingdo = malloc(50); >Why not just have 'char kingdo[50]' if you're going to set an arbitrary >size? > >> bzero(kingdo, strlen(kingdo)); >Not sure what bzero does. > >> char *kingdo; >> >> sprintf(kingdo, "%s",king(ch,"no Kingdom",TRUE)); >> sprintf(buf, "%sYou are a member of %s.\r\n",buf,kingdo); >You're using an uninitialised pointer. You need to either set a certain >amount that 'kingdo' can be (e.g. char kingdo[50]), or malloc it. Don't >you think it would be much more efficient to have an array of string with >the kingdoms, and define each kingdom as a number that matches the slot >in the array and reference it by the define? i.e. > >#define KINGDOM_UNDEFINED -1 >#define KINGDOM_WHATEVER 0 >#define KINGDOM_SOMETHING 1 >... >#define MAX_KINGDOMS // Whatever number is greater than the last > // kingdom number. > >char *kingdoms[MAX_KINGDOMS] = { >"Something", >"Whatever", >... >"Last kingdom" >}; > >sprintf(kingdo, "You are a member of the %s kingdom", >kingdoms[GET_KINGDOM(ch)]); > >-- end mailer code -- > >--- >Jon Nielsen <nikolai@montana.com> >"To acquire knowledge, one must study; but to >aquire wisdom, one must observe." > -Marilyn vos Savant > Also on the following line: char *king(struct char_data * chh, char *cp, int p) ^^^ ||| Please note you have 2 h's. Usually a char_data function is 1 h, unless this is totally different. -CyberMan (who may not really know) ______________________________________________________ Get Your Private, Free Email at http://www.hotmail.com +------------------------------------------------------------+ | Ensure that you have read the CircleMUD Mailing List FAQ: | | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html | +------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/15/00 PST