Solved

Using the posix fnmatch to compare to an empty string

Posted on 2013-01-21
2
320 Views
Last Modified: 2013-11-13
I have a lot of code that uses the fnmatch C function to match strings against patterns.

From time to time I want to match against empty strings, but the wildcard * relates to one or more characters, not zero characters.

I was sure you could achieve a pattern to match all blank strings with

!(?*)

meaning any string that is not one character or more in length, but this does not match.

What is the "right" way to get a match from:

fnmatch(..., "", 0)

where ... is the pattern?
0
Comment
Question by:gazillabyte
2 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 150 total points
Comment Utility
fnmatch("", "", 0)
0
 

Author Comment

by:gazillabyte
Comment Utility
Cheers.

I had a wrapper around fnmatch which checked the length of the pattern and the string and returned false if they were both empty. It must have seemed like a good idea at the time ;-)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
fix34  challenge 9 95
userCompare  challenge 3 61
PHP question(s) about order of output 9 39
creating threads in delphi 1 52
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
"Disruption" is the most feared word for C-level executives these days. They agonize over their industry being disturbed by another player - most likely by startups.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now