관리 메뉴

開發

[C] STRCMP 본문

1.윈도우/5.C

[C] STRCMP

벅스쭌 2010.08.16 10:20
strcmp(비교대상1, 비교대상2);

비교대상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

'1.윈도우 > 5.C' 카테고리의 다른 글

[C] STRCMP  (0) 2010.08.16
[C] 파일 입출력  (0) 2010.08.16
0 Comments
댓글쓰기 폼