moving upper case names to lower case

Steven Weintraub stevenw at oakhill.UUCP
Thu Aug 24 00:07:08 AEST 1989


In article <9326 at chinet.chi.il.us>, john at chinet.chi.il.us (John Mundt) writes:
> In article <20672 at adm.BRL.MIL> Leisner.Henr at xerox.com (Marty) writes:
> >I'm looking for a good, clean way to move files from upper case names
> >to lower case names.
> >i.e. FOO.C to foo.c
> >I could always right a C program, but there gotta be a better way.

> #include <stdio.h>
> #include <ctype.h>
> 
> main()
> {
> 	register int c;
> 	while ((c = getchar()) != EOF)
> 		putchar(tolower(c));
> }

I should point out there is a risk in using tolower like this.  Some
machines define tolower as ((c)-'A'+'a') (like some sun systems).
This works well if the character is an upper case letter but it will
translate 'FOO.c' to 'fooN^C'.  Some things are never so easy.  I
thus use (for portability):

#define to_lower(c)  (isupper(c):tolower(c)?(c))

(of course this to fails if you send in *p++, UHG!!)

                   enough from this mooncalf - Steven
----------------------------------------------------------------------------
These opinions aren't necessarily Motorola's or Remora's - but I'd like to
think we share some common views.
----------------------------------------------------------------------------
Steven R Weintraub                             | O Lord,
...!cs.utexas.edu!oakhill!stevenw              |   let me talk gently,
Motorola Inc.  Austin, Texas                   | for I might have to eat my
(512) 891-3023 (office) (512) 453-6953 (home)  |   words tomorrow.
----------------------------------------------------------------------------



More information about the Comp.lang.c mailing list