C Language and Libraries Help (clang.hlp) (
Table of Contents;
Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
CMPSTR.C
◄Up► ◄Contents► ◄Index► ◄Back►
─────Run-Time Library───────────────────────────────────────────────────────
/* CMPSTR.C illustrates string and memory comparison functions including:
* memcmp _memicmp
* strncmp _strnicmp
* strcmp _stricmp _strcmpi
*/
#include <memory.h>
#include <string.h>
#include <stdio.h>
char string1[] = "The quick brown dog jumps over the lazy fox";
char string2[] = "The QUICK brown fox jumps over the lazy dog";
void main()
{
char tmp[20];
int result;
printf( "Compare strings:\n\t\t%s\n\t\t%s\n\n", string1, string2 );
printf( "Function:\tmemcmp\n" );
result = _memcmp( string1, string2 , 42 );
if( result > 0 )
strcpy( tmp, "greater than" );
else if( result < 0 )
strcpy( tmp, "less than" );
else
strcpy( tmp, "equal to" );
printf( "Result:\t\tString 1 is %s string 2\n\n", tmp );
printf( "Function:\t_memicmp\n" );
result = _memicmp( string1, string2, 42 );
if( result > 0 )
strcpy( tmp, "greater than" );
else if( result < 0 )
strcpy( tmp, "less than" );
else
strcpy( tmp, "equal to" );
printf( "Result:\t\tString 1 is %s string 2\n\n", tmp );
printf( "Function:\tstrncmp\n" );
result = strncmp( string1, string2 , 42 );
if( result > 0 )
strcpy( tmp, "greater than" );
else if( result < 0 )
strcpy( tmp, "less than" );
else
strcpy( tmp, "equal to" );
printf( "Result:\t\tString 1 is %s string 2\n\n", tmp );
printf( "Function:\_tstrnicmp\n" );
result = _strnicmp( string1, string2, 42 );
if( result > 0 )
strcpy( tmp, "greater than" );
else if( result < 0 )
strcpy( tmp, "less than" );
else
strcpy( tmp, "equal to" );
printf( "Result:\t\tString 1 is %s string 2\n\n", tmp );
printf( "Function:\tstrcmp\n" );
result = strcmp( string1, string2 );
if( result > 0 )
strcpy( tmp, "greater than" );
else if( result < 0 )
strcpy( tmp, "less than" );
else
strcpy( tmp, "equal to" );
printf( "Result:\t\tString 1 is %s string 2\n\n", tmp );
printf( "Function:\t_stricmp or _strcmpi\n" );
result = _stricmp( string1, string2 );
/* _strcmpi (commented out) is the same as _stricmp.
result = _strcmpi( string1, string2 );
*/
if( result > 0 )
strcpy( tmp, "greater than" );
else if( result < 0 )
strcpy( tmp, "less than" );
else
strcpy( tmp, "equal to" );
printf( "Result:\t\tString 1 is %s string 2\n", tmp );
}
-♦-