Is there a good example of how toupper() works?

Mark Brader msb at sq.sq.com
Tue Oct 23 03:06:46 AEST 1990


My previous posting misspelled CHAR_MAX and UCHAR_MAX.  What I meant
to say was, of course, this:

	#ifdef __STDC__			/* ANSI C */
	# if (CHAR_MAX < UCHAR_MAX)	/* chars are signed */
	#   define TOUPP(c) ((c) < 0? (c): toupper((c)))
	# else
	#   define TOUPP(c) toupper((c))
	# endif
	#else
	# define TOUPP(c) ((isascii((c)) && islower((c))? toupper((c)): ((c)))
	#endif

	for (p = duh; *p != '\0'; ++p)
		*p = TOUPP(*p);

-- 
Mark Brader		   "I don't care HOW you format   char c; while ((c =
SoftQuad Inc., Toronto	    getchar()) != EOF) putchar(c);   ... this code is a
utzoo!sq!msb, msb at sq.com    bug waiting to happen from the outset." --Doug Gwyn

This article is in the public domain.



More information about the Comp.lang.c mailing list