Another message.......

John Love-Jensen eljay@adobe.com
Thu Feb 7 08:44:00 GMT 2002


Hi Kabir,

fprintf(stream,"%s", (strcmp(szCountry,"ID")==0 ||
strcmp(szCountry,"FE")==0)
  ? toupper(pNote)
  : pNote);

The toupper(pNote) function is not what you want.

The toupper() function takes a character (passed as an int), and outputs an
uppercase character (returned as an int).

int toupper(int c);

When you call it like this:
toupper(pNote)

It will treat the pNote pointer as an int (oh oh!), and convert whatever
happenstance value the pointer-turned-int has into an uppercase value, and
return it as an int.

Your ternary expression has the signature:
bool ? int : char*

That doesn't satisfy the criteria of what a ternary must have.  The two
conditional clauses must both evaluate to the same (more-or-less) type.

What you want is:
bool ? char* : char*

You'll need to write your own pToUpper function.  Something like...
char* pToUpper(char* s)
{
    while(*s) {
        if(isascii(*s)) {
            // toupper is only valid if isascii is true.
            *s++ = toupper(*s);
        }
    }
    return s;
}

Note:  this is an IN PLACE transform, which means it mutates the passed in
variable (or, in this case, the data pointed to by the passed in variable).
By some programming paradigms, such an action is dangerous and should be
commented with big flashing warning signs.

Sincerely,
--Eljay




More information about the Gcc-help mailing list