Solved

Using the posix fnmatch to compare to an empty string

Posted on 2013-01-21
2
324 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
ID: 38803689
fnmatch("", "", 0)
0
 

Author Comment

by:gazillabyte
ID: 38804077
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Sorting in Excel with Group Headers if the Exist 2 89
word0 challenge 3 91
Microsoft C++ code failing in executable that worked 9 97
Image decoding from Camera 3 85
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
"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…

786 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