ANA() SANA() Macros are wrong...

From: Peter Ajamian (peter@pajamian.dhs.org)
Date: 03/10/01


#define ANA(obj) (strchr("aeiouyAEIOUY", *(obj)->name) ? "An" : "A")
#define SANA(obj) (strchr("aeiouyAEIOUY", *(obj)->name) ? "an" : "a")

Try this:  obj->name = "yoyo".

You'll get: "an yoyo", which is incorrect.  In fact I can't at them
moment think of a noun or adjective that starts with a "y" that would be
preceded by "an", that's not to say there isn't one, though.  In this
case the "y" is not acting as a vowel, but as a consonant, so "a" is
correct, not "an".

Unfotunately, I don't have an english primer to check and I don't know
off the top of my head what exactly defines "y" to be a vowel, I think it
acts as a vowel in the abscence of other vowels, if that's the case then
the following (while being rather more complex) should work...

#define VOWEL_LEADER(name) (strchr("aeiouAEIOU", *(name)) || \
        (strchr("yY", *(name)) && !(name)[strcspn((name), "aeiouAEIOU")]))
#define ANA(obj) (VOWEL_LEADER((obj)->name) ? "An" : "A")
#define SANA(obj) (VOWEL_LEADER((obj)->name) ? "an" : "a")

Note that strcspn() returns an index into the first arg of the first
character that matches one of the characters in the second, it includes
the trailing null in both, so I'm using the return value to index the
first arg and if the result is null then I know that a match was not
found.

Regards, Peter

--
   +---------------------------------------------------------------+
   | 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/04/01 PST