Is there a good example of how toupper() works?
michelle international krill lee
mikey at ontek.com
Thu Oct 18 14:06:18 AEST 1990
In comp.lang.c, edh at ux.acs.umn.edu (Eric D. Hendrickson) writes:
|
| #include <ctype.h>
| main()
| {
| char *duh = "Hello";
| printf("%s\n", duh);
| while (*duh <= strlen(duh)) {
| if (islower(*duh)) *duh = toupper(*duh);
| *duh++;
| }
| printf("%s\n", duh);
| }
The usual suspects have pointed out the obvious problems; thus
the only things remaining are nitpicky in the extreme, but that
never stopped me from posting before...
1. While not a problem in this context, it's generally advisable
to use isascii() to check that whatever is being converted to
upper case is actually an ascii character.
2. My manual page makes reference to a _toupper() macro. Adding
an "#ifdef _toupper" to check if the macro is available could
speed things up marginally, at the expense of defeating what-
ever locale facility is available.
3. Making "duh" a register variable wouldn't hurt, especially if
the above code were to be completely debugged and turned into
a more general utility.
4. Modification of the constant character array "Hello" may be a
no-no for certain compilers and/or certain compiler options.
5. An exit or a return statement would be nice.
6. #includ-ing <stdio.h> is consider good practice in code which
uses the standard i/o facilities like printf().
More information about the Comp.lang.c
mailing list