Automatic Filename Extensions

David Camp C04661DC%WUVMD.BITNET at CUNYVM.CUNY.EDU
Mon Apr 11 06:10:02 AEST 1988


     A programming technique I have frequently used is:

if (strchr (filename, '.') == NULL)
    strcat (filename, ".EXT");

in order to implement default filename extensions.  If the user
wanted to specify a filename with no extension, he simply ends
it with a '.' character.

     I recently realized that this fails for the odd filename
with '.' in the path, such as ".filename" or "..filename".
To fix it, I shall use:

if (filename [strlen (filename) - 1] != '.')
    strcat (filename, ".EXT");

I hope this is helpful to others struggling to get it right.
-David-

*----------------------------------------------------------------------*
| (314) 362-3635                  Mr. David J. Camp                    |
|                          ^      Division of Biostatistics, Box 8067  |
| Room 1108D             < * >    Washington University Medical School |
| 706 South Euclid         v      660 South Euclid                     |
|                                 Saint Louis, MO 63110                |
| Bitnet: C04661DC at WUVMD.BITNET                                        |
| Internet: C04661DC%WUVMD.BITNET at CUNYVM.CUNY.EDU                      |
*----------------------------------------------------------------------*



More information about the Comp.lang.c mailing list