Archive for March, 2015

3/6: Quick Wildcard String Compare

UncategorizedShawnNo Comments

Here is a quick function the will allow wildcard comparison.

#include < stdio.h >
 
int striwildcmp( const char *test, const char *value )
{
  int result = 0;
  if( test == value ) {
    return 0;
  }
  if( !test ) {
    return -1;
  }
  if( !value ) {
    return 1;
  }
  while( result == 0 ) {    
    // Skip '?' wildcard
    if( *test != '?' ) {
      result = tolower( *test ) - tolower( *value );
    }
    // Break once you compare a null terminator
    if( (*test == '\0') ||  *value == '\0'  ) {
      break;
    }    
    ++test;
    ++value;
  }
  return result;
}

Read the rest of this entry »