November 2004
Intermediate to advanced
736 pages
14h 4m
English
There is more to comparing strings than strcmp() or even strncmp(). Linux provides several general string-matching functions that make your programming tasks simpler. We start with the simple tasks and then cover the more complex ones.
Chapter 14 explains how to glob file names using the glob() function, but people used to globbing capabilities sometimes wish to apply them to other sorts of strings. The fnmatch() function allows you to apply globbing rules to arbitrary strings:
#include <fnmatch.h> int fnmatch(const char *pattern, const char *string, int flags);
The pattern is a standard glob expression with four special characters, modified by the flags argument:
| Matches any string, including ... |