Path: utzoo!mnetor!uunet!husc6!cmcl2!brl-adm!adm!C04661DC%WUVMD.BITNET@CUNYVM.CUNY.EDU From: C04661DC%WUVMD.BITNET@CUNYVM.CUNY.EDU (David Camp) Newsgroups: comp.lang.c Subject: Automatic Filename Extensions Message-ID: <12901@brl-adm.ARPA> Date: 10 Apr 88 20:10:02 GMT Sender: news@brl-adm.ARPA Lines: 29 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@WUVMD.BITNET | | Internet: C04661DC%WUVMD.BITNET@CUNYVM.CUNY.EDU | *----------------------------------------------------------------------*