Re: your mail

From: Tel Janin Aellinsar (icarus@Loomis.Berkshire.NET)
Date: 04/08/96

On Mon, 8 Apr 1996, The Gathering MUD wrote:

> Hello..  i have a question..
>     sprintf(buf2, "%s[ Exits: %s]%s\r\n", CCCYN(ch, C_NRM),
> +->	  *buf ? buf : "None! ", CCNRM(ch, C_NRM));

>     Would someone please explain to me what this line does?  It is from
>     act.informative.c, in the autoexit code, around line 300

expr ? true : false

expr:  A standard if/while/for/etc expression.  In this case, if *buf is
       nonzero, it means TRUE.

true:  What the statement evaluates to if expr is TRUE.

false: What the statement evaluates to if expr is FALSE.

Here, if *buf is nonzero (or non-null-terminator, presumably), buf is 
added to the string.  These should be the exits.  If not, the string 
"None!" is added instead.  It's a handy way of doing things in one step 
without if's, though it's a bit confusing until it's been explained.  
(Sorry about the 'expr' stuff, btw, I learned this from a Borland manual.)

Tel Janin Aellinsar             
McCoy Enterprises Corporation          Shayol Ghul Resort and Health Spa
Berserker Dragon, Knights of the Cosmos             icarus@BERKSHIRE.NET

This archive was generated by hypermail 2b30 : 12/18/00 PST