string comparisons in C
Leo de Wit
leo at philmds.UUCP
Fri Jul 14 21:54:51 AEST 1989
In article <44672745.14a1f at gtephx.UUCP> covertr at gtephx.UUCP (Richard E. Covert) writes:
| But, I was browsing thru the MWC manual, and lo and behold I see
|pnmatch(). Now pnmatch is a wonderful little function which does string
|comparisons. And it even accepts wildcards, so I was in business. I just
|build an array of strings such as "*.PI1", and then by looping thru the
|array I can string compare a user inputted filename against the list of
|legal filetypes. Pretty neat solution.
|
| So, the moral of this little ditty, is READ YOUR MANUAL!!
|
|P.S. Does anyone know if pnmatch() is implemented on other C compilers??
Lattice C has stcpm() and stcpma() for unanchored and anchored pattern
matching. The BSD C libraries have regcomp() and regex() for regular
expression pattern matching (which probably goes a lot further than
any of pnmatch(), stcpm() or stcpma()).
The drawback of all these wonderful functions is that they are hardly
standardized, so you loose if portability is at stake (and it is more
often than you'd hope for). For maximum portability, use the functions
that are in the ANSI draft, and create your own library for functions
like pnmatch() that aren't there (it is very easy to make a general
wildcard pattern matcher). You'll be grateful for this advice when
you switch to another compiler, or your vendor doesn't support this
neat little function in the next release, or you're porting to a
different system, or ...
Leo.
More information about the Comp.lang.c
mailing list