Thread: Wildcard string matching

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    54

    Wildcard string matching

    Hi:

    So I'm trying to match a string against a wildcard to see whether they match. I'm using a snippet found here: http://www.planet-source-code.com/vb...=1680&lngWId=3

    However, this doesn't seem to be working. My code implementation is as follows:

    Code:
    for (int i = 0; i < allFiles.size(); i++)
    			{
    				char *buf1 = new char[allFiles[i].size() + 1];
    				char *buf2 = new char[files.size() + 1];
    
    				strcpy(buf1, allFiles[i].c_str());
    				strcpy(buf2, files.c_str());
    				cout <<allFiles[i] <<" " <<wildcmp(buf1, buf2) <<endl;
    				if (wildcmp(buf1, buf2))
    				{
    					searchFile(allFiles[i]);
    				}
    			}
    allFiles is a vector with a directory listing of that directory. files is a string containing the wildcard (so like t*.cpp).

    Please let me know what's going on. wildcmp always returns 0.

    Thanks.
    -Zack

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Looking at the snippet from the site, I think you passed the strings backwards. The string with wildcards is the first parameter, while what you want to match it against is next.

  3. #3
    Registered User
    Join Date
    May 2005
    Posts
    54
    Quote Originally Posted by citizen
    Looking at the snippet from the site, I think you passed the strings backwards. The string with wildcards is the first parameter, while what you want to match it against is next.
    Good point. That fixed it .
    -Zack

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    BTW, if wildcmp took const char*, you wouldn't have to copy the C++ strings into the character arrays. You might be able to just add the const and it would still compile so you can pass the result of c_str() directly to that function.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  2. RicBot
    By John_ in forum C++ Programming
    Replies: 8
    Last Post: 06-13-2006, 06:52 PM
  3. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 11:06 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM