Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: C newb - Part III - find a .jhr file in a directory - seg fault Date: Fri, 23 Dec 2016 14:13:25 -0800 Organization: None to speak of Lines: 27 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="df4a13e992574b38b1b7cd38c2b29037"; logging-data="15409"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX187k2k67tcka001LgC2JEk5" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:uPgdIaCK7Psa65K6oFjxIgsyIm4= sha1:oWT82nuuRm0pg2MewkR2w0TEfcY= Xref: csiph.com comp.lang.c:100096 BartC writes: > On 12/12/2016 17:58, S390 wrote: >> finding all *.jhr in a directory > >> while ((dir = readdir(d)) != NULL) >> { >> ret = strchr(dir->d_name, ch); >> printf("String after |%c| is - |%s|\n", ch, ret); >> >> //if (strcmp(dir->d_name,"TESTJAMNNTPD.jhr") == 0) // > > > Have a look at the 'fnmatch()' function which will do wildcard matching > for you. Something like: > > if (fnmatch("*.jhr", dir->d_name, 0)) ... > > 'man fnmatch' for further details. Be aware that fnmatch() is defined by POSIX, not by ISO C, and it might not be available on all systems. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"