[Gllug] Re: [OxLUG] C function strcasecmp

tet at accucard.com tet at accucard.com
Fri Jul 20 10:46:18 UTC 2001


>has it... but looking in my copy of the c programming language strcmp is
>like 3 lines of code, you could just modify the s[i]==t[i] test to take
>account of the ascii 65 to ascii 97 gap?
>
>s[i]==t[i] || s[i]-32==t[i] || s[i]+32==t[i]
>
>would be a (very broken) example?

<pedant>

Your solution only works if you're using an ASCII based character set.
strcasecmp() should work even if you're using EBCDIC or some other
mutant. In reality, it won't matter, because virtually nothing in the
Unix world uses EBCDIC. Even Linux on the S390 doesn't stoop that low,
although I don't know about UTS (Amdahl's mainframe Unix).

BTW, adding and subtracting 32 -- bleugh. That's what bitwise logical
operators are for :-)

	(0x20 | s[i]) == (0x20 | t[i])

Of course, it still only works with ASCII...

</pedant>

Tet

-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list