Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!ontek!mikey From: mikey@ontek.com (michelle (international krill) lee) Newsgroups: comp.lang.c Subject: Re: Is there a good example of how toupper() works? Message-ID: <1482@ontek.com> Date: 18 Oct 90 04:06:18 GMT References: <2466@ux.acs.umn.edu> Organization: Ontek Corporation -- Laguna Hills, California Lines: 38 In comp.lang.c, edh@ux.acs.umn.edu (Eric D. Hendrickson) writes: | | #include | 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 is consider good practice in code which uses the standard i/o facilities like printf().