It's clearly doing everything in ASCII:
strcasecmp("Z", "0") 122
It's interesting. I use the same compare function for both a sort and for a
binary search, so it all works correctly -- it's just not working the way I
think it is.
Charles
-----Original Message-----
From: IBM Mainframe Discussion List [mailto:[email protected]] On
Behalf Of Charles Mills
Sent: Thursday, June 1, 2017 11:44 AM
To: [email protected]
Subject: strcasecmp() comparing punctuation in ASCII?
I am getting some odd results out of the C library function strcasecmp().
Does someone want to tell me if they see pilot error here?
(For anyone not familiar, strcasecmp() is documented as
https://www.ibm.com/support/knowledgecenter/SSLTBW_2.2.0/com.ibm.zos.v2r2.bp
xbd00/rsrccm.htm .)
I have the following debug code running:
printf("strcasecmp(\"%%\", \"*\") %d\n", strcasecmp("%", "*"));
(Try to read past all of the escaping in the string. The string is
effectively 'strcasecmp("%", "*")'.
And here are the results:
strcasecmp("%", "*") -37
4AA988A8899476764757546FF44
02393125347DFCFB0FCFD003700
It is saying that % (X'6C') is less than * (X'5C').
Why do I think it's ASCII rather than just a plain old bug? Because
ultimately what I am doing is sorting a table. And here is the sort order I
end up with:
%, *, +, -, /, //
That's wrong for EBCDIC but perfect for ASCII.
Yes, it's running on z/OS. No, I'm not doing anything weird with LOCALE.
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN