O'Reilly logo

Linux Application Development, Second Edition by Erik W. Troan, Michael K. Johnson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 23. String Matching

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.

Globbing Arbitrary Strings

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required