Computer/초보자를 위한 C 언어 300제
061. 문자열을 일정 크기만큼 비교하기(strcmp)
Theo Kim
2011. 1. 30. 18:14
#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, 3 ); if( ret == 0 ) { printf( "%3.3s == %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 ); }