Desc :

int strcmp(const char* src1, const char* src2);

 

모든 문자열이 일치 = 0

src1가 큰 경우 = 1

src1가 작은 경우 = -1

 

*** 대소문자 구분함 ***

 


Source Code :

#include<stdio.h>
#include<string.h>

#define SKY "sky"

void main()
{
	char string[100];
	int ret;

	printf("영단어를 입력한 후 enter키를 치세요 \n");
	printf("sky를 입력하면 프로그램이 종료됩니다\n");

	while (1)
	{
		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);
		}
	}
}

 


Result :

+ Recent posts