Subject: [lojban] Re: C question: How to or strings and get a string?

From: Robin Lee Powell <[email-masked]>
Date: Thu, 23 Jan 2003 09:41:42 -0800

On Thu, Jan 23, 2003 at 09:39:21AM -0800, Robin Lee Powell wrote:
> On Wed, Jan 22, 2003 at 10:26:16PM -0500, Pierre Abbat wrote:
> > I am very close to having a tolpo'u a'o ke valfendi mutmi'i. There are
> > a few lines in the program that I'm not sure how to fix:
> > 
> > #define is3rafsi(str) (monmapti("ICV",str) || monmapti("CVC",str) || monmapti("CUV",str))
> > #define is4rafsi(str) (monmapti("CVCC",str) || monmapti("ICVC",str))
> > #define isgismu(str) (monmapti("CVCCV",str) || monmapti("ICVCV",str))
> > 
> > monmapti returns NULL if it didn't match or a pointer to the first
> > character after the matching string if it does. is3rafsi is supposed
> > to do the same, but instead it returns 1, 
> 
> Of course it does. You're asking for a boolean OR. Any non-zero in C
> is boolean TRUE. A boolean operator that returns true returns 1, IIRC.
> 
> I'm not sure what the problem is.
> 
> If you want to return one or the other of a couple of options depending
> on whether the first is true, you want:
> 
> #define is4rafsi(str) (monmapti("CVCC",str) ? monmapti("CVCC",str): monmapti("ICVC",str))
> 
> IIRC.

For reference:

http://www.eskimo.com/~scs/C-faq/q9.2.html

-Robin

-- 
http://www.digitalkingdom.org/~rlpowell/ *** I'm a *male* Robin.
.i le pamoi velru'e zo'u crepu le plibu taxfu
.i le remoi velru'e zo'u mo .i le cimoi velru'e zo'u ba'e prali .uisai
http://www.lojban.org/ *** to sa'a cu'u lei pibyta'u cridrnoma toi