Path: utzoo!mnetor!uunet!steinmetz!davidsen From: davidsen@steinmetz.ge.com (William E. Davidsen Jr) Newsgroups: comp.lang.c Subject: Re: Automatic Filename Extensions Message-ID: <10355@steinmetz.ge.com> Date: 11 Apr 88 14:47:51 GMT References: <12901@brl-adm.ARPA> Reply-To: davidsen@crdos1.UUCP (bill davidsen) Organization: General Electric CRD, Schenectady, NY Lines: 22 In article <12901@brl-adm.ARPA> C04661DC%WUVMD.BITNET@CUNYVM.CUNY.EDU (David Camp) writes: | [...] | 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"); in UNIX that's fine, a name like a.b may have .EXT added, but it won't work on other systems, such as MSDOS and VMS. How about isolating just the filename via strrchr (or rindex) and then using strchr as you have been. Something like: char *temp; if ((temp = strrchr(filename, '/')) == NULL) temp = filename; if (strchr(temp, '.') == NULL) strcat (temp, ".EXT"); Of course you can do this in one statement without the temp if you use nested ?:, but I won't put that code over my .sig. -- bill davidsen (wedu@ge-crd.arpa) {uunet | philabs | seismo}!steinmetz!crdos1!davidsen "Stupidity, like virtue, is its own reward" -me