반응형
strcmp(비교대상1, 비교대상2);
비교대상1 > 비교대상2 = 1
비교대상1 = 비교대상2 = 0
비교대상1 < 비교대상2 = -1
비교대상1 > 비교대상2 = 1
비교대상1 = 비교대상2 = 0
비교대상1 < 비교대상2 = -1
/* STRCMP.C */ #include출력#include char string1[] = "The quick brown dog jumps over the lazy fox"; char string2[] = "The QUICK brown dog jumps over the lazy fox"; void main( void ) { char tmp[20]; int result; /* Case sensitive */ printf( "Compare strings:\n\t%s\n\t%s\n\n", string1, string2 ); 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( "\tstrcmp: String 1 is %s string 2\n", tmp ); /* Case insensitive (could use equivalent _stricmp) */ result = _stricmp( string1, string2 ); if( result > 0 ) strcpy( tmp, "greater than" ); else if( result < 0 ) strcpy( tmp, "less than" ); else strcpy( tmp, "equal to" ); printf( "\t_stricmp: String 1 is %s string 2\n", tmp ); }
Compare strings:
The quick brown dog jumps over the lazy fox
The QUICK brown dog jumps over the lazy fox
strcmp: String 1 is greater than string 2
_stricmp: String 1 is equal to string 2
The quick brown dog jumps over the lazy fox
The QUICK brown dog jumps over the lazy fox
strcmp: String 1 is greater than string 2
_stricmp: String 1 is equal to string 2
반응형
'→ 개발 > C' 카테고리의 다른 글
[C] 파일 입출력 (0) | 2010.08.16 |
---|