برنامه ای که نحوه عملکرد دو تابع strncmp و _strnicmp (در کامپایلر های بورلند: strnicmp) را نشان میدهد.

#include <iostream.h>
#include <string.h>

void main(void)
{
    char string1[]="The quick brown dog jumps over the lazy fox";
    char string2[]="The QUICK brown fox jumps over the lazy dog";
    char tmp[20];
    int result;
     cout<<"Compare strings:\n\t\tString1= "<<string1
          <<"\n\t\tString2= "<<string2<<"\n\n";
cout<<"Function:\tstrncmp(first 10 characters only)\n";
     result = strncmp( string1, string2 , 10 );
      if( result > 0 )
            strcpy( tmp, "greater than" );
      else if( result < 0 )
            strcpy( tmp, "less than" );
      else
             strcpy( tmp, "equal to" );
    cout<<"Result:\t\tString 1 is "<<tmp<<" string 2\n\n";
cout<<"Function:\t_strnicmp (first 10 characters only)";
     result = strnicmp( string1, string2, 10 );
      if( result > 0 )
            strcpy( tmp, "greater than" );
      else if( result < 0 )
            strcpy( tmp, "less than" );
      else
            strcpy( tmp, "equal to" );
cout<<"\nResult:\t\tString 1 is "<<tmp<<" string 2\n\n";
}


//end