Computer/초보자를 위한 C 언어 300제
059. 문자열을 대·소문자로 구분하여 비교하기(strcmp)
Theo Kim
2011. 1. 30. 17:58
#include <stdio.h>
#include <string.h>
#define SKY "sky"
void main( void )
{
char string[100];
int ret;
printf( "영단어를 입력한 후 Enter키를 치세요!\n" );
printf( "sky를 입력하면 프로그램이 종료됩니다. \n" );
do
{
gets( string );
ret = strcmp( string, SKY );
if( ret == 0 )
{
printf( "%s == %s, ret = %d \n", string, SKY, ret );
break;
}
else if( ret < 0 ) printf( "%s < %s, ret = %d \n", string, SKY, ret );
else printf( "%s > %s, ret = %d \n", string, SKY, ret );
} while( 1 );
}