16,471
社区成员
发帖
与我相关
我的任务
分享
// crt_strcmp.c
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
char string1[] = "The quick brown dog jumps over the lazy fox";
char string2[] = "The QUICK brown dog jumps over the lazy fox";
int main( void )
{
char tmp[20];
int result;
// Case sensitive
printf( "Compare strings:\n %s\n %s\n\n", string1, string2 );
result = strcmp( string1, string2 );
if( result > 0 )
strcpy_s( tmp, _countof(tmp), "greater than" );
else if( result < 0 )
strcpy_s( tmp, _countof (tmp), "less than" );
else
strcpy_s( tmp, _countof (tmp), "equal to" );
printf( " strcmp: String 1 is %s string 2\n", tmp );
// Case insensitive (could use equivalent _stricmp)
result = _stricmp( string1, string2 );
if( result > 0 )
strcpy_s( tmp, _countof (tmp), "greater than" );
else if( result < 0 )
strcpy_s( tmp, _countof (tmp), "less than" );
else
strcpy_s( tmp, _countof (tmp), "equal to" );
printf( " _stricmp: String 1 is %s string 2\n", tmp );
}